NDBM and ME
Chris Torek
torek at elf.ee.lbl.gov
Sat May 11 16:08:01 AEST 1991
In article <ADRIANHO.91May10173137 at barkley.berkeley.edu>
adrianho at barkley.berkeley.edu (Adrian J Ho) writes:
[a bunch of correct stuff]
>You now have a single string with all 4 fields that can be used in an
>NDBM record.
Note that ndbm places a (fairly small) limit on the size of any
single <key+content> pair (4096 bytes, minus overhead; this comes
to 4090 bytes for a page with one pair [1 count + 2 offsets, all
shorts, consumes 6 bytes]).
In general, you hand ndbm a blob of bytes as a content and a
separate blob of bytes as a key. Some arbitrary time later, you
hand ndbm a blob of bytes as a key and it gives you back a blob
of bytes as a content. The returned content is *not* at the same
`place' as the original, and is probably not at the same alignment.
Thus, for instance,
datum.dptr = (char *)&foo;
datum.size = sizeof(int);
err = store(key, datum);
is OK, but
datum = fetch(key);
if (datum.dptr == NULL) ... handle not found ...;
if (datum.dsize != sizeof(int)) ... handle corrupted database ...;
foo = *(int *)datum.dptr;
is not, because `datum.dptr' may not be correctly aligned.
--
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA Domain: torek at ee.lbl.gov
More information about the Comp.unix.programmer
mailing list