,I8Berkeley DB Reference Guide: Architecture[P2

Berkeley DB Reference Guide: Architecture



$

Available APIs

C

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

C++

GThe C++ classes provide a thin wrapper around the C API, with the majorAadvantages being improved encapsulation and an optional exceptionBmechanism for errors. C++ applications use a single include file,#include <db_cxx.h>.@

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

JAs a rule, each C++ object has exactly one structure from the underlying CAPI associated with it.GThe C structure is allocated with each constructor call and deallocatedwith each destructor call.GThus, the rules the user needs to follow in allocating and deallocating9structures are the same between the C and C++ interfaces.

FTo ensure portability to many platforms, both new and old, we make few/assumptions about the C++ compiler and library.KFor example, we do not expect STL, templates or namespaces to be available.FThe newest C++ feature used is exceptions, which are used liberally totransmit error information.?Even the use of exceptions can be disabled at runtime, by usingset_error_model.

JAVA

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

KAs in C++, each Java object has exactly one structure from the underlying CNAPI associated with it. The Java structure is allocated with each constructorNor open call, but is deallocated only when the Java garbage collector does so.HBecause the timing or ordering of garbage collection is not predictable,the user should takeGcare to do a close when finished with any object that has such amethod.



Dbm/Ndbm, Hsearch

jBerkeley DB supports the standard UNIX interfaces dbm/ndbm and8hsearch.gAfter including a new header file and recompiling, dbm/ndbmBprograms will run orders of magnitude faster and their underlyingfdatabases can grow as large as you like (historic dbm/ndbmDapplications will fail when some number of entries are inserted intoBthe database, where the number depends on the effectiveness of the-hashing function on the particular data set).

MAJÿÿ