3
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
4
<!--All rights reserved.-->
5
<!--See the file LICENSE for redistribution information.-->
8
<title>Berkeley DB: DB->set_alloc</title>
9
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
10
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
13
<a name="2"><!--meow--></a>
14
<table width="100%"><tr valign=top>
16
<h1>DB->set_alloc</h1>
19
<a href="../api_c/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
27
DB->set_alloc(DB *db,
28
void *(*app_malloc)(size_t),
29
void *(*app_realloc)(void *, size_t),
30
void (*app_free)(void *));
33
<p>Set the allocation functions used by the <a href="../api_c/env_class.html">DB_ENV</a> and <a href="../api_c/db_class.html">DB</a>
34
methods to allocate or free memory owned by the application.
35
<p>There are a number of interfaces in Berkeley DB where memory is allocated by
36
the library and then given to the application. For example, the
37
<a href="../api_c/dbt_class.html#DB_DBT_MALLOC">DB_DBT_MALLOC</a> flag, when specified in the <a href="../api_c/dbt_class.html">DBT</a> object,
38
will cause the <a href="../api_c/db_class.html">DB</a> methods to allocate and reallocate memory
39
which then becomes the responsibility of the calling application. (See
40
<a href="../api_c/dbt_class.html">DBT</a> for more information.) Other examples are the Berkeley DB
41
interfaces which return statistical information to the application:
42
<a href="../api_c/db_stat.html">DB->stat</a>, <a href="../api_c/lock_stat.html">DB_ENV->lock_stat</a>, <a href="../api_c/log_archive.html">DB_ENV->log_archive</a>,
43
<a href="../api_c/log_stat.html">DB_ENV->log_stat</a>, <a href="../api_c/memp_stat.html">DB_ENV->memp_stat</a>, and <a href="../api_c/txn_stat.html">DB_ENV->txn_stat</a>. There is
44
one interface in the Berkeley DB where memory is allocated by the application
45
and then given to the library: <a href="../api_c/db_associate.html">DB->associate</a>.
46
<p>On systems in which there may be multiple library versions of the
47
standard allocation routines (notably Windows NT), transferring memory
48
between the library and the application will fail because the Berkeley DB
49
library allocates memory from a different heap than the application uses
50
to free it. To avoid this problem, the <a href="../api_c/env_set_alloc.html">DB_ENV->set_alloc</a> and
51
DB->set_alloc methods can be used to pass Berkeley DB references to the
52
application's allocation routines.
53
<p>It is not an error to specify only one or two of the possible allocation
54
function arguments to these interfaces; however, in that case the
55
specified interfaces must be compatible with the standard library
56
interfaces, as they will be used together. The functions specified
57
must match the calling conventions of the ANSI C X3.159-1989 (ANSI C) library routines
59
<p>Because databases opened within Berkeley DB environments use the allocation
60
interfaces specified to the environment, it is an error to attempt to
61
set those interfaces in a database created within an environment.
62
<p>The DB->set_alloc interface may not be called after the <a href="../api_c/db_open.html">DB->open</a>
64
<p>The DB->set_alloc method returns a non-zero error value on failure and 0 on success.
66
<p>The DB->set_alloc method may fail and return a non-zero error for the following conditions:
68
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
69
<p>Called in a database environment.
70
<p>Called after <a href="../api_c/db_open.html">DB->open</a> was called.
72
<p>The DB->set_alloc method may fail and return a non-zero error for errors specified for other Berkeley DB and C library or system functions.
73
If a catastrophic error has occurred, the DB->set_alloc method may fail and
74
return <a href="../ref/program/errorret.html#DB_RUNRECOVERY">DB_RUNRECOVERY</a>,
75
in which case all subsequent Berkeley DB calls will fail in the same way.
77
<a href="../api_c/db_class.html">DB</a>
79
<a href="../api_c/db_list.html">Databases and Related Methods</a>
81
<table width="100%"><tr><td><br></td><td align=right>
82
<a href="../api_c/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
84
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>