开发者

Android - dictionary file. Which is faster, database or reading file directly?

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开发者_StackOverflow社区 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:

  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.

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.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜