Sqlite在C#中将数据库移动到内存
Sqlite Move Database to Memory in C#
如何在 C# 中将 sqlite 磁盘数据库移动到内存?
我需要将数据库从磁盘打开到内存数据库以加快操作速度,并在完成工作后将其保存回文件。
磁盘数据库是一个空数据库,我想将数据从一个List转移到内存数据库,并用它来对非常大的数据进行排序,这会杀死List.Sort功能。数据排序后,我不再需要数据库了。
恐怕你不能do that。而且我不建议这样做,你为什么不增加缓存大小?
An SQLite database is normally stored in a single ordinary disk file.
However, in certain circumstances, the database might be stored in
memory.
The most common way to force an SQLite database to exist purely in
memory is to open the database using the special filename ":memory:".
In other words, instead of passing the name of a real disk file into
one of the sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2()
functions, pass in the string ":memory:". For example:
并且每个到 SQlite
的连接都会创建一个单独的新数据库。
rc = sqlite3_open(":memory:", &db); When this is done, no disk file is
opened. Instead, a new database is created purely in memory. The
database ceases to exist as soon as the database connection is closed.
Every :memory: database is distinct from every other. So, opening two
database connections each with the filename ":memory:" will create two
independent in-memory databases.
如果你要实现这样的东西,没有任何官方方法可以做到!但是你可以:
- 打开一个新的 in-memory 数据库
- 将文件数据库中的所有数据复制到内存
- 比较并合并new/deleted/updated数据从内存到磁盘
以SQLite
文件打开为in-memory
的C语言代码为例:
https://www.mail-archive.com/sqlite-users@mailinglists.sqlite.org/msg15929.html
如何在 C# 中将 sqlite 磁盘数据库移动到内存?
我需要将数据库从磁盘打开到内存数据库以加快操作速度,并在完成工作后将其保存回文件。
磁盘数据库是一个空数据库,我想将数据从一个List转移到内存数据库,并用它来对非常大的数据进行排序,这会杀死List.Sort功能。数据排序后,我不再需要数据库了。
恐怕你不能do that。而且我不建议这样做,你为什么不增加缓存大小?
An SQLite database is normally stored in a single ordinary disk file. However, in certain circumstances, the database might be stored in memory.
The most common way to force an SQLite database to exist purely in memory is to open the database using the special filename ":memory:". In other words, instead of passing the name of a real disk file into one of the sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2() functions, pass in the string ":memory:". For example:
并且每个到 SQlite
的连接都会创建一个单独的新数据库。
rc = sqlite3_open(":memory:", &db); When this is done, no disk file is opened. Instead, a new database is created purely in memory. The database ceases to exist as soon as the database connection is closed. Every :memory: database is distinct from every other. So, opening two database connections each with the filename ":memory:" will create two independent in-memory databases.
如果你要实现这样的东西,没有任何官方方法可以做到!但是你可以:
- 打开一个新的 in-memory 数据库
- 将文件数据库中的所有数据复制到内存
- 比较并合并new/deleted/updated数据从内存到磁盘
以SQLite
文件打开为in-memory
的C语言代码为例:
https://www.mail-archive.com/sqlite-users@mailinglists.sqlite.org/msg15929.html