|
![]() ![]() ![]() |
The Berkeley DB subsystems can be accessed through interfaces from multiple languages. The standard library interface is ANSI C. Applications can also use Berkeley DB via C++ or Java, as well as from scripting languages. Environments can be shared among applications written using any of theses APIs. For example, you might have a local server written in C or C++, a script for an administrator written in Perl or Tcl, and a web based user interface written in Java, all sharing a single database environment.
#include <db.h>
#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, Berkeley DB makes as few assumptions as possible about the C++ compiler and library. For example, it does 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.
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 by the Java garbage collector. Because the timing of garbage collection is not predictable, applications should take care to do a close when finished with any object that has a close method.
![]() ![]() ![]() |