~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/docs/ref/arch/apis.html

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.-->
 
4
<html>
 
5
<head>
 
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++">
 
9
</head>
 
10
<body bgcolor=white>
 
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>
 
15
</td></tr></table>
 
16
<p>
 
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
 
25
database environment.
 
26
<h3>C</h3>
 
27
<p>The Berkeley DB library is written entirely in ANSI C.  C applications use a
 
28
single include file:
 
29
<p><blockquote><pre>#include &lt;db.h&gt;</pre></blockquote>
 
30
<h3>C++</h3>
 
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 &lt;db_cxx.h&gt;</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.
 
51
<h3>Java</h3>
 
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
 
56
exceptions.
 
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>
 
73
</td></tr></table>
 
74
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
 
75
</body>
 
76
</html>