Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btr ee,hash,hashing,transaction,transactions,locking,logging,access method,access me thods,java,C,C++

### Berkeley DB Reference Guide: Architecture

# Available APIs

# C

The Berkeley DB library is written entirely in ANSI C. C applications use a single include file, #include <db.h>.

# C++

The C++ classes provide a thin wrapper around the C API, with the major advantages being improved encapsulation and an optional exception mechanism for errors. C++ applications use a single include file, #include <db_cxx.h>.

The classes and methods are named in a fashion that directly corresponds to structures and functions in the C interface. Likewise, arguments to methods appear in the same order as the C interface, except to remove the explicit this pointer. The #defines used for flags are identical between the C and C++ interfaces.

As a rule, each C++ object has exactly one structure from the underlying C API associated with it. The C structure is allocated with each constructor call and deallocated with each destructor call. Thus, the rules the user needs to follow in allocating and deallocating structures are the same between the C and C++ interfaces.

To ensure portability to many platforms, both new and old, we make few assumptions about the C++ compiler and library. For example, we do not expect STL, templates or namespaces to be available. The newest C++ feature used is exceptions, which are used liberally to transmit error information. Even the use of exceptions can be disabled at runtime, by using set_error_model.

# JAVA

The Java classes provide a layer around the C API that is almost identical to the C++ layer. The classes and methods are, for the most part identical to the C++ layer. Db constants and #defines are represented as "static final int" values. Errors conditions appear as Java exceptions.

As in C++, each Java object has exactly one structure from the underlying C API associated with it. The Java structure is allocated with each constructor or open call, but is deallocated only when the Java garbage collector does so. Because the timing or ordering of garbage collection is not predictable, the user should take care to do a close when finished with any object that has such a method.

# Dbm/Ndbm, Hsearch

Berkeley DB supports the standard UNIX interfaces dbm/ndbm and hsearch. After including a new header file and recompiling, dbm/ndbm programs will run orders of magnitude faster and their underlying databases can grow as large as you like (historic dbm/ndbm applications will fail when some number of entries are inserted into the database, where the number depends on the effectiveness of the hashing function on the particular data set).