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