1<!--$Id: env_set_alloc.so,v 1.24 2008/01/19 14:12:57 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB: DB_ENV->set_alloc</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<table width="100%"><tr valign=top> 12<td> 13<b>DB_ENV->set_alloc</b> 14</td> 15<td align=right> 16<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a> 17<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td> 18</tr></table> 19<hr size=1 noshade> 20<tt> 21<b><pre> 22#include <db.h> 23<p> 24int 25DB_ENV->set_alloc(DB_ENV *dbenv, 26 void *(*app_malloc)(size_t), 27 void *(*app_realloc)(void *, size_t), 28 void (*app_free)(void *)); 29</pre></b> 30<hr size=1 noshade> 31<b>Description: DB_ENV->set_alloc</b> 32<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> 33methods to allocate or free memory owned by the application.</p> 34<p>There are a number of interfaces in Berkeley DB where memory is allocated by 35the library and then given to the application. For example, the 36<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, 37will cause the <a href="../api_c/db_class.html">DB</a> methods to allocate and reallocate memory 38which then becomes the responsibility of the calling application. (See 39<a href="../api_c/dbt_class.html">DBT</a> for more information.) Other examples are the Berkeley DB 40interfaces which return statistical information to the application: 41<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>, 42<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 one 43method in Berkeley DB where memory is allocated by the application and then 44given to the library: <a href="../api_c/db_associate.html">DB->associate</a>.</p> 45<p>On systems in which there may be multiple library versions of the 46standard allocation routines (notably Windows NT), transferring memory 47between the library and the application will fail because the Berkeley DB 48library allocates memory from a different heap than the application uses 49to free it. To avoid this problem, the DB_ENV->set_alloc and 50<a href="../api_c/db_set_alloc.html">DB->set_alloc</a> methods can be used to pass Berkeley DB references to the 51application's allocation routines.</p> 52<p>It is not an error to specify only one or two of the possible allocation 53function parameters to these interfaces; however, in that case the 54specified interfaces must be compatible with the standard library 55interfaces, as they will be used together. The functions specified must 56match the calling conventions of the ANSI C X3.159-1989 (ANSI C) library routines of 57the same name.</p> 58<p>The DB_ENV->set_alloc method configures operations performed using the specified 59<a href="../api_c/env_class.html">DB_ENV</a> handle, not all operations performed on the underlying 60database environment.</p> 61<p>The DB_ENV->set_alloc method may not be called after the <a href="../api_c/env_open.html">DB_ENV->open</a> method is 62called. 63</p> 64<p>The DB_ENV->set_alloc method 65returns a non-zero error value on failure 66and 0 on success. 67</p> 68<b>Parameters</b> <br> 69 <b>app_malloc</b><ul compact><li>The <b>app_malloc</b> parameter is the application-specified malloc 70function.</ul> 71 <b>app_realloc</b><ul compact><li>The <b>app_realloc</b> parameter is the application-specified realloc 72function.</ul> 73 <b>app_free</b><ul compact><li>The <b>app_free</b> parameter is the application-specified free function.</ul> 74<br> 75<br><b>Errors</b> 76<p>The DB_ENV->set_alloc method 77may fail and return one of the following non-zero errors:</p> 78<br> 79<b>EINVAL</b><ul compact><li>If the method was called after <a href="../api_c/env_open.html">DB_ENV->open</a> was called; or if an 80invalid flag value or parameter was specified.</ul> 81<br> 82<hr size=1 noshade> 83<br><b>Class</b> 84<a href="../api_c/env_class.html">DB_ENV</a> 85<br><b>See Also</b> 86<a href="../api_c/env_list.html">Database Environments and Related Methods</a> 87</tt> 88<table width="100%"><tr><td><br></td><td align=right> 89<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a> 90</td></tr></table> 91<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 92</body> 93</html> 94