<!--$Id: env_set_alloc.so,v 1.13 2002/08/24 18:22:35 bostic Exp $--> <!--Copyright 1997-2002 by Sleepycat Software, Inc.--> <!--All rights reserved.--> <!--See the file LICENSE for redistribution information.--> <html> <head> <title>Berkeley DB: DB_ENV->set_alloc</title> <meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> <meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++"> </head> <body bgcolor=white> <a name="2"><!--meow--></a> <table width="100%"><tr valign=top> <td> <h1>DB_ENV->set_alloc</h1> </td> <td align=right> <a href="../../db4-devel-4.1.25/api_c/c_index.html"><img src="../../db4-4.1.25/images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../../db4-4.1.25/images/ref.gif" alt="Ref"></a> </td></tr></table> <hr size=1 noshade> <tt> <h3><pre> #include <db.h> <p> int DB_ENV->set_alloc(DB_ENV *db, void *(*app_malloc)(size_t), void *(*app_realloc)(void *, size_t), void (*app_free)(void *)); </pre></h3> <h1>Description</h1> <p>Set the allocation functions used by the <a href="../../db4-devel-4.1.25/api_c/env_class.html">DB_ENV</a> and <a href="../../db4-devel-4.1.25/api_c/db_class.html">DB</a> methods to allocate or free memory owned by the application. <p>There are a number of interfaces in Berkeley DB where memory is allocated by the library and then given to the application. For example, the <a href="../../db4-devel-4.1.25/api_c/dbt_class.html#DB_DBT_MALLOC">DB_DBT_MALLOC</a> flag, when specified in the <a href="../../db4-devel-4.1.25/api_c/dbt_class.html">DBT</a> object, will cause the <a href="../../db4-devel-4.1.25/api_c/db_class.html">DB</a> methods to allocate and reallocate memory which then becomes the responsibility of the calling application. (See <a href="../../db4-devel-4.1.25/api_c/dbt_class.html">DBT</a> for more information.) Other examples are the Berkeley DB interfaces which return statistical information to the application: <a href="../../db4-devel-4.1.25/api_c/db_stat.html">DB->stat</a>, <a href="../../db4-devel-4.1.25/api_c/lock_stat.html">DB_ENV->lock_stat</a>, <a href="../../db4-devel-4.1.25/api_c/log_archive.html">DB_ENV->log_archive</a>, <a href="../../db4-devel-4.1.25/api_c/log_stat.html">DB_ENV->log_stat</a>, <a href="../../db4-devel-4.1.25/api_c/memp_stat.html">DB_ENV->memp_stat</a>, and <a href="../../db4-devel-4.1.25/api_c/txn_stat.html">DB_ENV->txn_stat</a>. There is one interface in the Berkeley DB where memory is allocated by the application and then given to the library: <a href="../../db4-devel-4.1.25/api_c/db_associate.html">DB->associate</a>. <p>On systems in which there may be multiple library versions of the standard allocation routines (notably Windows NT), transferring memory between the library and the application will fail because the Berkeley DB library allocates memory from a different heap than the application uses to free it. To avoid this problem, the DB_ENV->set_alloc and <a href="../../db4-devel-4.1.25/api_c/db_set_alloc.html">DB->set_alloc</a> methods can be used to pass Berkeley DB references to the application's allocation routines. <p>It is not an error to specify only one or two of the possible allocation function arguments to these interfaces; however, in that case the specified interfaces must be compatible with the standard library interfaces, as they will be used together. The functions specified must match the calling conventions of the ANSI C X3.159-1989 (ANSI C) library routines of the same name. <p>The DB_ENV->set_alloc method configures operations performed using the specified <a href="../../db4-devel-4.1.25/api_c/env_class.html">DB_ENV</a> handle, not all operations performed on the underlying database environment. <p>The DB_ENV->set_alloc interface may not be called after the <a href="../../db4-devel-4.1.25/api_c/env_open.html">DB_ENV->open</a> interface is called. <p>The DB_ENV->set_alloc method returns a non-zero error value on failure and 0 on success. <h1>Errors</h1> <p>The DB_ENV->set_alloc method may fail and return a non-zero error for the following conditions: <p><dl compact> <p><dt>EINVAL<dd>An invalid flag value or parameter was specified. <p>Called after <a href="../../db4-devel-4.1.25/api_c/env_open.html">DB_ENV->open</a> was called. </dl> <p>The DB_ENV->set_alloc method may fail and return a non-zero error for errors specified for other Berkeley DB and C library or system functions. If a catastrophic error has occurred, the DB_ENV->set_alloc method may fail and return <a href="../../db4-devel-4.1.25/ref/program/errorret.html#DB_RUNRECOVERY">DB_RUNRECOVERY</a>, in which case all subsequent Berkeley DB calls will fail in the same way. <h1>Class</h1> <a href="../../db4-devel-4.1.25/api_c/env_class.html">DB_ENV</a> <h1>See Also</h1> <a href="../../db4-devel-4.1.25/api_c/env_list.html">Database Environments and Related Methods</a> </tt> <table width="100%"><tr><td><br></td><td align=right> <a href="../../db4-devel-4.1.25/api_c/c_index.html"><img src="../../db4-4.1.25/images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../../db4-4.1.25/images/ref.gif" alt="Ref"></a> </td></tr></table> <p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font> </body> </html>