2
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
4
<!--See the file LICENSE for redistribution information.-->
7
<title>Berkeley DB Reference Guide: Programmatic APIs</title>
8
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
12
<a name="2"><!--meow--></a>
13
<table width="100%"><tr valign=top>
14
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Architecture</dl></h3></td>
15
<td align=right><a href="../../ref/arch/progmodel.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/arch/script.html"><img src="../../images/next.gif" alt="Next"></a>
18
<h1 align=center>Programmatic APIs</h1>
19
<p>The Berkeley DB subsystems can be accessed through interfaces from multiple
20
languages. The standard library interface is ANSI C. Applications can
21
also use Berkeley DB via C++ or Java, as well as from scripting languages.
22
Environments can be shared among applications written by using any of
23
theses APIs. For example, you might have a local server written in C
24
or C++, a script for an administrator written in Perl or Tcl, and a
25
Web-based user interface written in Java -- all sharing a single
28
<p>The Berkeley DB library is written entirely in ANSI C. C applications use a
30
<p><blockquote><pre>#include <db.h></pre></blockquote>
32
<p>The C++ classes provide a thin wrapper around the C API, with the major
33
advantages being improved encapsulation and an optional exception
34
mechanism for errors. C++ applications use a single include file:
35
<p><blockquote><pre>#include <db_cxx.h></pre></blockquote>
36
<p>The classes and methods are named in a fashion that directly corresponds
37
to structures and functions in the C interface. Likewise, arguments to
38
methods appear in the same order as the C interface, except to remove the
39
explicit <b>this</b> pointer. The #defines used for flags are identical
40
between the C and C++ interfaces.
41
<p>As a rule, each C++ object has exactly one structure from the underlying
42
C API associated with it. The C structure is allocated with each
43
constructor call and deallocated with each destructor call. Thus, the
44
rules the user needs to follow in allocating and deallocating structures
45
are the same between the C and C++ interfaces.
46
<p>To ensure portability to many platforms, both new and old, Berkeley DB makes
47
as few assumptions as possible about the C++ compiler and library. For
48
example, it does not expect STL, templates, or namespaces to be
49
available. The newest C++ feature used is exceptions, which are used
50
liberally to transmit error information. Even the use of exceptions
51
can be disabled at runtime.
53
<p>The Java classes provide a layer around the C API that is almost identical
54
to the C++ layer. The classes and methods are, for the most part
55
identical to the C++ layer. Berkeley DB constants and #defines are represented as
56
"static final int" values. Error conditions are communicated as Java
58
<p>As in C++, each Java object has exactly one structure from the underlying
59
C API associated with it. The Java structure is allocated with each
60
constructor or open call, but is deallocated only by the Java garbage
61
collector. Because the timing of garbage collection is not predictable,
62
applications should take care to do a close when finished with any object
63
that has a close method.
64
<h3>Dbm/Ndbm, Hsearch</h3>
65
<p>Berkeley DB supports the standard UNIX interfaces <a href="../../api_c/dbm.html">dbm</a>, <a href="../../api_c/dbm.html">ndbm</a>,
66
and <a href="../../api_c/hsearch.html">hsearch</a>. After including a new header file and recompiling,
67
programs will run orders of magnitude faster, and underlying databases
68
can grow as large as necessary. Also, historic <a href="../../api_c/dbm.html">dbm</a> and
69
<a href="../../api_c/dbm.html">ndbm</a> applications can fail once some number of entries are
70
inserted into the database, in which the number depends on the
71
effectiveness of the internal hashing function on the particular data
72
set. This is not a problem with Berkeley DB.
73
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/arch/progmodel.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/arch/script.html"><img src="../../images/next.gif" alt="Next"></a>
75
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>