Subj : store collections of strings in tdb or gdbm To : comp.programming From : Lasse Kliemann Date : Fri Oct 07 2005 10:22 pm Greetings, my data is organized as follows: - There are several records. - Each record consists of a fixed number of strings. Strings may contain arbitrary characters, even null characters. I use the stralloc implementation (http://cr.yp.to/lib/stralloc.html) to realize this. In particular, string length is limited by the size of an unsigned int. - A key is associated with each record. Keys are also given as strallocs. The data shall be stored in a database like tdb (http://sourceforge.net/projects/tdb/), which has an interface very similar to that of gdbm. To this end, each record has to be encoded in a structure like this (taken from tdb's manual pages): typedef struct { char *dptr; size_t dsize; } TDB_DATA; I cannot simply concatenate the strings and put them into the dptr, because I would not find their ends and beginnings later (because the strings may contain null characters). My idea so far for each record: - Get the decimal representation of all the lengths of the strings in the record. - Write these into dptr, as null-terminated strings. - Then write all the strings into dptr. It is obvious how to get the strings back from this encoding. My questions now are: - How elegant is my approach? - Is the conversion into the decimal representation necessary, or can I write the lengths of the strings as unsinged ints into dptr? Would this be portable? - Hasn't this been done before and exists in form of a library? Thanks for your advice! Lasse .