A Fistful of DBM's
December 18, 2000
When Perl stores your hash to disk using dbmopen, it is
actually relying on a particular DBM system, known as either ODBM or
NDBM. The latter, or the "old DBM", was the original DBM system
distributed with Perl. Newer implementations of Perl use NDBM or --
wait for it -- the "new DBM". The old DBM, for example, was slower.
The new DBM is faster. Also, the old DBM had a very limited storage
capacity -- less than 1K for each value. The new DBM supports storage
capacities ranging from 1 to 4K depending on the Perl
distribution.
Yet, ODBM and NDBM aren't the only DBM's out there. You can
actually use any available DBM to tie your hash to disk. Other DBM's
may offer advantages in speed, or storage capacity, or other features
that we'll soon see. Remember that DBM's are independent of and
incompatible with each other, and if you tie a hash to one type of
DBM, you can't simply use that hash with another DBM system.
Many Perl distributions come with additional DBM's, or you can
find them at
CPAN, the Perl module repository.
In particular, four alternative DBM's are commonly used with
Perl.
SDBM is the "simple DBM", and is optimized for speed with a
small storage capacity per value. Worth considering for large hashes
with small values.
GDBM is the Gnu Free Software Foundation implementation of
DBM. It offers several advances over the other DBM's, including
compatibility with GDBM databases used on many platforms. GDBM is
also very fast, and features some synchronization support for shared
DBM's which may be accessed by multiple users simultaneously.
DB_File is the module name for BerkeleyDB version 1. This
is an even more sophisticated DBM which is fast, supports large
values, and offers several different storage architectures: normal
hashes, BTrees, and disk-based arrays. We'll take a closer look at
DB_File shortly.
BerkeleyDB is the DBM module for BerkeleyDB versions 2 and 3. As
you can imagine, these DBM's are the most advanced, and are
evolutions from version 1 of this software.
The Humble Hash as DB
The Perl You Need to Know
Tie a Yellow Ribbon ...
|