2
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
4
<!--See the file LICENSE for redistribution information.-->
7
<title>Berkeley DB: DbEnv::set_alloc</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>
15
<h1>DbEnv::set_alloc</h1>
18
<a href="../api_cxx/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
23
#include <db_cxx.h>
26
typedef void *(*db_malloc_fcn_type)(size_t);
27
typedef void *(*db_realloc_fcn_type)(void *, size_t);
28
typedef void *(*db_free_fcn_type)(void *);
32
DbEnv::set_alloc(db_malloc_fcn_type app_malloc,
33
db_realloc_fcn_type app_realloc,
34
db_free_fcn_type app_free);
37
<p>Set the allocation functions used by the <a href="../api_cxx/env_class.html">DbEnv</a> and <a href="../api_cxx/db_class.html">Db</a>
38
methods to allocate or free memory owned by the application.
39
<p>There are a number of interfaces in Berkeley DB where memory is allocated by
40
the library and then given to the application. For example, the
41
<a href="../api_cxx/dbt_class.html#DB_DBT_MALLOC">DB_DBT_MALLOC</a> flag, when specified in the <a href="../api_cxx/dbt_class.html">Dbt</a> object,
42
will cause the <a href="../api_cxx/db_class.html">Db</a> methods to allocate and reallocate memory
43
which then becomes the responsibility of the calling application. (See
44
<a href="../api_cxx/dbt_class.html">Dbt</a> for more information.) Other examples are the Berkeley DB
45
interfaces which return statistical information to the application:
46
<a href="../api_cxx/db_stat.html">Db::stat</a>, <a href="../api_cxx/lock_stat.html">DbEnv::lock_stat</a>, <a href="../api_cxx/log_archive.html">DbEnv::log_archive</a>,
47
<a href="../api_cxx/log_stat.html">DbEnv::log_stat</a>, <a href="../api_cxx/memp_stat.html">DbEnv::memp_stat</a>, and <a href="../api_cxx/txn_stat.html">DbEnv::txn_stat</a>. There is
48
one interface in the Berkeley DB where memory is allocated by the application
49
and then given to the library: <a href="../api_cxx/db_associate.html">Db::associate</a>.
50
<p>On systems in which there may be multiple library versions of the
51
standard allocation routines (notably Windows NT), transferring memory
52
between the library and the application will fail because the Berkeley DB
53
library allocates memory from a different heap than the application uses
54
to free it. To avoid this problem, the DbEnv::set_alloc and
55
<a href="../api_cxx/db_set_alloc.html">Db::set_alloc</a> methods can be used to pass Berkeley DB references to the
56
application's allocation routines.
57
<p>It is not an error to specify only one or two of the possible allocation
58
function arguments to these interfaces; however, in that case the
59
specified interfaces must be compatible with the standard library
60
interfaces, as they will be used together. The methods specified
61
must match the calling conventions of the ANSI C X3.159-1989 (ANSI C) library routines
63
<p>The DbEnv::set_alloc method configures operations performed using the specified
64
<a href="../api_cxx/env_class.html">DbEnv</a> handle, not all operations performed on the underlying
66
<p>The DbEnv::set_alloc interface may not be called after the <a href="../api_cxx/env_open.html">DbEnv::open</a>
68
<p>The DbEnv::set_alloc method either returns a non-zero error value or throws an exception that
69
encapsulates a non-zero error value on failure, and returns 0 on success.
71
<p>The DbEnv::set_alloc method may fail and throw an exception or return a non-zero error for the following conditions:
73
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
74
<p>Called after <a href="../api_cxx/env_open.html">DbEnv::open</a> was called.
76
<p>The DbEnv::set_alloc method may fail and throw an exception or return a non-zero error for errors specified for other Berkeley DB and C library or system methods.
77
If a catastrophic error has occurred, the DbEnv::set_alloc method may fail and
78
either return <a href="../ref/program/errorret.html#DB_RUNRECOVERY">DB_RUNRECOVERY</a> or throw a
79
<a href="../api_cxx/runrec_class.html">DbRunRecoveryException</a>,
80
in which case all subsequent Berkeley DB calls will fail in the same way.
82
<a href="../api_cxx/env_class.html">DbEnv</a>
84
<a href="../api_cxx/env_list.html">Database Environments and Related Methods</a>
86
<table width="100%"><tr><td><br></td><td align=right>
87
<a href="../api_cxx/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
89
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>