我存储数据的方式可能存在问题..?
我正在开发一个android应用程序,这里我有一些数据对象(1000秒)..到目前为止,我将它们放在hashTable中并将hashtable存储在一个文件..我对我所做的并不是很满意,因为它可能会增加堆大小(?)并且应用程序可能会开始冻结(至少当有太多数据对象时。 .)
我的问题是,这是一个存储数据的好方法,我的应用程序是否有可能崩溃或变慢...
谢谢..
I'm working on an android app and here i have few data objects (1000 s).. as of now i put them in hashTable and store hashtable in a file.. i'm not really satisfied with what i have done since it may increase heap size (?) and app may start freezing (Atleast when there are too many data objects..)
my question is , is this a good way to store data and are there any chances that my app will crash or slow down...
Thank you..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要决定哪些数据需要保留在内存中(您的应用程序需要快速访问的数据),以及哪些数据需要存储以便在需要时检索。
通常,我会认为应用程序将其所有数据存储在数据库中,并且您将仅在内存中加载最有可能将使用的数据。
最有可能取决于您的应用程序,您可能希望冒险加载不会使用的数据(消耗更多内存但具有更好的性能),或者您可能会采取相反的方向。
数据存储在文件中,不在Java堆中,变量和对象存在于堆中,文件则不然。
并且您应该考虑使用 SQLite 而不是文件。
First you need to decide which data needs to be kept in memory (the data that your application needs to access quickly), and what data needs to be stored to be retrieved once needed.
Typically, I would think of the application having all its data stored on the database, and you would load in memory only the data that are most-likely going to be used.
That most-likely depends on your application, you might want to risk loading data that are not going to be used (consuming more memory but having a better performance), or you might go the opposite direction.
The data stored on a file, are not in the Java Heap, variables and objects exists in the heap, files don't.
And you should consider using SQLite instead of a file.