简体   繁体   English

我应该使用数组还是数据库

[英]Should I use array or database

I am writing an app that contains a list of items with their information. 我正在编写一个包含项目列表及其信息的应用程序。 When the users open the app, they would see the list, and when they select a particular item, they would get all the information about that item. 当用户打开应用程序时,他们将看到列表,并且当他们选择特定项目时,他们将获得有关该项目的所有信息。

Right now my approach is I store the data in a multidimensional array in the java source file. 现在,我的方法是将数据存储在java源文件中的多维数组中。 When I push a new update, I might add new items in the java source file (so the array gets bigger). 当我推送新更新时,我可能会在Java源文件中添加新项(因此数组会变大)。 I wonder if this is the best approach. 我想知道这是否是最好的方法。 I tried looking up relevant information about array and database on the Internet, but I can't seem to find the information I need. 我尝试在Internet上查找有关阵列和数据库的相关信息,但似乎找不到所需的信息。 Any advice for me? 有什么建议吗?

Also, if in the future, I create a function for users to add their own items to the list, what's the impact? 另外,如果将来我创建一个函数供用户将自己的项目添加到列表中,会产生什么影响?

If the user should be able to update it, if you should be able to update it dynamically (for instance update from internet), then the database is a must. 如果用户应该能够更新它,如果您应该能够动态更新它(例如从Internet更新),那么数据库是必须的。

If that data is static and won't change unless you update the app, you can store it in the code or better, in a file (you can store in JSON format for ease of reading & parsing) 如果该数据是静态的并且除非您更新应用程序否则不会更改,则可以将其存储在代码中或更好的文件格式中(可以以JSON格式存储,以便于读取和解析)

如果使用数组,则用户重新添加的项目将在应用重启时消失。

您可以使用直接存储在手机上的SQLite数据库(例如SD卡)。

An analysis of the storage options and what they're commonly used for can be found here . 您可以在此处找到有关存储选项及其常用功能的分析。 Personally I suggest SQLite database. 我个人建议使用SQLite数据库。

The database is good for permanent data, but realize it can create a bottleneck if writing to disk is not really necessary. 该数据库可用于永久性数据,但要意识到,如果确实没有必要写入磁盘,则数据库可能会造成瓶颈。

I am in the middle of refactoring an App to no longer use SQLite. 我正在重构应用程序以不再使用SQLite。 I was inserting large amounts(10,000-100,000) of new rows at once, and it looked like it was going to take an hour based on my log feedback of the status. 我一次插入大量(10,000-100,000)新行,根据状态的日志反馈,似乎要花一个小时。 When I keep it in memory, it all loaded in about 5 seconds. 当我将其保存在内存中时,它们全部在大约5秒钟内加载完毕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM