https://helpful.knobs-dials.com/index.php/File_database_notes
Simple
file database
l Concurrent write access for multiple processes
Simple file databases are
useful to persist data with little required structure, and for goals that
require storing (large amounts of) data on disk with pretty quick hash-based
lookups.
Many such databases are based directly or less directly on the
old, simple, yet effective dbm, a (family of) database engine(s) that
stores key-value mappings (both strings) in a file (sometimes two, splitting
out some metadata/index(verify)).
Implementations usually hashing for fast retrieval, allows
rebucketing to have the hashing scale well, and fixed-size buckets to allow
relatively efficient modification.
https://edoras.sdsu.edu/doc/gdbm/
有優缺點的分析。
Thus gdbm is an excellent lightweight alternative to a full
relational database. If all you need
to do is to store arbitrary data to be looked up with keys, and do it fast,
then gdbm is your solution. However, there are a few caveats.
gdbm_fetch()
需要注意的地方!要記得釋放記憶體。
When gdbm fetches a datum from a file, it malloc
s the
buffer for you and returns the datum -- but that means, of course, that you have to free the buffer yourself!
Failure to do so, as always, will work fine until you go into production and
everybody's watching, at which point your process will crash and burn from the
memory leaks.