如何在SQLite数据库和内存使用之间做出决定 [英] How to decide between SQLite database vs. in-memory usage

查看:310
本文介绍了如何在SQLite数据库和内存使用之间做出决定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个离开公司的同事那里继承了一个项目.在检查他的代码时,我感到有些困惑.从服务器接收到大量数据后,他将这些数据保存到客户端中的数据库中,然后继续在db上处理这些数据.在应用程序开始时就接收一次数据.我不明白的是,为什么他不只是使用内存中的数据,而是需要将其存储在db上?

I inherited a project from a colleague that left the company. While examining his code, I got confused by something. After he receives quite a big amount of data from the server, he saves this data to a database in the client and then he goes on to work with this data on db. The data is received once at the beginning of the application. What I could not understand that much is, why isn't he just using the data from the memory but needs to store this on db?

在应用程序内部,有许多内存密集型操作,例如使用Quartz查看大型pdf文件,但是,sqlite的大小不也算作应用程序的内存使用量吗?我的意思是您认为这样做的好处是什么?

Inside the application there are many memory intensive operations like viewing big pdf files using Quartz and so, but isn't the sqlite's size also counted as the memory usage of the app? I mean what do you think the advantage of this could be?

推荐答案

SQLite自身加载时的占用空间很小(〜250-400Kb).当SQLite与磁盘数据库一起使用时,由于它没有内存开销,它甚至不计文件大小(默认情况下,数据库可以在其表中容纳约1Tb的数据).正如您所说,它是持久的数据存储.

SQLite have very small footprint when load itself (~250-400Kb). When SQLite work with on-disk database, there is no memory overhead because of it, it don't even meter size of the file (by default database can hold about 1Tb of data in it's tables). And as you said, it's persistent data storage.

对于内存数据库存储,您的应用程序将消耗

In case of in-memory database store, your application wil consume

memory = database file size + small overhead

您在内存数据库中执行的查询也会受到一定的限制(我不记得我在街上的时间了,但是您不能使用事务处理和清理)

Also yo will get some amount of limitations with queries you can perform on in-memory database (I can't remember for time I on the street, but you can't use transactions and vacuum)

将SQLite与磁盘数据库一起使用,与尝试使用文件存储数据集相比,您将获得更快的数据访问权限和更少的占用空间

Use SQLite with on-disk database and you will gain faster data access and lower footprint than trying to use files to store set of data

这篇关于如何在SQLite数据库和内存使用之间做出决定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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