JojoLinkyBob has asked for the wisdom of the Perl Monks concerning the following question:

I was tweaking some code today and noticed that although I'm adding more entries to my hash (using a DBM tie with SDBM_File option on WinNT), it didnt make my hash file any bigger...
It appears to be stuck on 1,047,552 bytes (which is exactly 1K shy of 1MB)

Am I losing data? or does this mean it stores everything in 1K chunks, and maybe the additional data I added to it wasn't enough to allocate another chunk?

Thanks, Desert coder

Replies are listed 'Best First'.
Re (tilly) 1: DBM Filesize limitation?
by tilly (Archbishop) on Jul 10, 2001 at 00:27 UTC
    Various dbm algorithms will free space by marking sections as free and then reuse that space on need. So just because you are adding data doesn't mean that it will need to grow.

    However you should know that SDBM_File is the worst of the dbm options available in Perl. It has a number of nasty limits, most importantly key/value pairs cannot exceed a fairly small size. If you can I strongly recommend using DB_File or GDBM_File. (I also recommend keeping a backup in plain text, but that is another story.)

Re: DBM Filesize limitation?
by no_slogan (Deacon) on Jul 10, 2001 at 00:12 UTC
    It's the chunks, and then some. A hash file is going to have empty space all over it. When you insert something, the hash algorithm picks a more-or-less random block to store it in. Only if that block happens to be full already will the file grow.

    OTOH, I've heard of hash algorithms that have problems when too many keys map to the same block. That has the effect of limiting your maximum file size, but the maximum size isn't something easy to compute. When in doubt, dump the values back out of the file to make sure they're really in there.