Android的 - 字典文件。这是更快,数据库或直接读取文件? [英] Android - dictionary file. Which is faster, database or reading file directly?

查看:538
本文介绍了Android的 - 字典文件。这是更快,数据库或直接读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Android的字典应用程序。该应用程序使用星际译王和DICT文件,这是通常pretty的大(10MB以上),并只包含明文。

I'm making an dictionary app for android. This app uses stardict and DICT files which is are often pretty large (10MB or more) and contains just plain texts.

当用户查找一个字,我的应用程序会随机读取文件并返回结果。我读过一些文章,读文件是昂贵的和缓慢的。所以我想如果把所有的数据到数据库是一个更好的解决方案?

When users look up a word, my app will read the file randomly and return the result. I've read on some articles that reading file is expensive and slow. So I wonder if bringing all data into database is a better solution?

推荐答案

我建议把你的话到数据库,原因如下:

I would suggest putting your words into a database for the following reasons:

    在Android上使用SQLite
  1. 在数据库查询不​​够快(〜1毫秒),即使是最没有耐心的用户
  2. 在读取大文件到内存在内存有限的环境中,如Android的一种危险的做法。
  3. 在试图到位的条目读出文件,而不是记忆有效地试图解决所有的SQLite已经解决了你的问题。
  1. DB lookups on android with SQLite are "fast enough" (~1ms) for even the most impatient of users
  2. Reading large files into memory is a dangerous practice in memory-limited environments such as android.
  3. Trying to read entries out of a file "in place" rather than "in memory" is effectively trying to solve all the problems that SQLite already solves for you.

psented使用数据库的唯一挑战$ P $与您所需要的数据对其进行初始化。这个问题的最好办法是建立事先所需的数据库,然后将其连接到您的APK资产来解决。有一个例子<一href="http://stackoverflow.com/questions/3013021/embed-a-database-in-the-apk-of-a-distributed-application-android">here这是相当不错的。

The only challenge presented in using a database is initializing it with the data you require. This problem can best be solved by creating the desired database in advance and then attaching it to your APK assets. There is an example here that is quite good.

希望这有助于。

这篇关于Android的 - 字典文件。这是更快,数据库或直接读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆