1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>DB_ENV->set_alloc()</title> 7 <link rel="stylesheet" href="apiReference.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Berkeley DB C API Reference" /> 10 <link rel="up" href="env.html" title="Chapter��5.�� The DB_ENV Handle" /> 11 <link rel="prev" href="envremove.html" title="DB_ENV->remove()" /> 12 <link rel="next" href="envset_app_dispatch.html" title="DB_ENV->set_app_dispatch()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DB_ENV->set_alloc()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="envremove.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��5.�� 23 The DB_ENV Handle 24 </th> 25 <td width="20%" align="right">��<a accesskey="n" href="envset_app_dispatch.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="envset_alloc"></a>DB_ENV->set_alloc()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db.h> 39 40int 41DB_ENV->set_alloc(DB_ENV *dbenv, 42 void *(*app_malloc)(size_t), 43 void *(*app_realloc)(void *, size_t), 44 void (*app_free)(void *)); </pre> 45 <p> 46 Set the allocation functions used by the <a class="link" href="env.html" title="Chapter��5.�� The DB_ENV Handle">DB_ENV</a> and 47 <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a> methods to allocate or free 48 memory owned by the application. 49 </p> 50 <p> 51 There are a number of interfaces in Berkeley DB where memory is 52 allocated by the library and then given to the application. For 53 example, the <a class="link" href="dbt.html#dbt_DB_DBT_MALLOC">DB_DBT_MALLOC</a> 54 flag, when specified in the <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a> 55 object, will cause the <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a> methods to allocate and 56 reallocate memory which then becomes the responsibility of the calling 57 application. Other examples are the Berkeley DB interfaces 58 which return statistical information to the application: 59 <a class="xref" href="dbstat.html" title="DB->stat()">DB->stat()</a>, 60 <a class="xref" href="lockstat.html" title="DB_ENV->lock_stat()">DB_ENV->lock_stat()</a>, 61 <a class="xref" href="logarchive.html" title="DB_ENV->log_archive()">DB_ENV->log_archive()</a>, 62 <a class="xref" href="logstat.html" title="DB_ENV->log_stat()">DB_ENV->log_stat()</a>, 63 <a class="xref" href="mempstat.html" title="DB_ENV->memp_stat()">DB_ENV->memp_stat()</a>, and 64 <a class="xref" href="txnstat.html" title="DB_ENV->txn_stat()">DB_ENV->txn_stat()</a>. There is 65 one method in Berkeley DB where memory is allocated by the application 66 and then given to the library: the callback specified to 67 <a class="xref" href="dbassociate.html" title="DB->associate()">DB->associate()</a>. 68 </p> 69 <p> 70 On systems in which there may be multiple library versions of the 71 standard allocation routines (notably Windows NT), transferring memory 72 between the library and the application will fail because the Berkeley 73 DB library allocates memory from a different heap than the application 74 uses to free it. To avoid this problem, the <code class="methodname">DB_ENV->set_alloc()</code> and 75 <a class="xref" href="dbset_alloc.html" title="DB->set_alloc()">DB->set_alloc()</a> 76 methods can be used to pass Berkeley DB references to the 77 application's allocation routines. 78 </p> 79 <p> 80 It is not an error to specify only one or two of the possible 81 allocation function parameters to these interfaces; however, in that 82 case the specified interfaces must be compatible with the standard 83 library interfaces, as they will be used together. The functions 84 specified must match the calling conventions of the ANSI C X3.159-1989 85 (ANSI C) library routines of the same name. 86 </p> 87 <p> 88 The <code class="methodname">DB_ENV->set_alloc()</code> method configures operations performed using 89 the specified <a class="link" href="env.html" title="Chapter��5.�� The DB_ENV Handle">DB_ENV</a> 90 handle, not all operations performed on the underlying database 91 environment. 92 </p> 93 <p> 94 The <code class="methodname">DB_ENV->set_alloc()</code> method may not be called after the 95 <a class="xref" href="envopen.html" title="DB_ENV->open()">DB_ENV->open()</a> method is called. 96 </p> 97 <p> 98 The <code class="methodname">DB_ENV->set_alloc()</code> <span> 99 <span> 100 method returns a non-zero error value on failure and 0 on success. 101 </span> 102 103 </span> 104 </p> 105 <div class="sect2" lang="en" xml:lang="en"> 106 <div class="titlepage"> 107 <div> 108 <div> 109 <h3 class="title"><a id="id1666608"></a>Parameters</h3> 110 </div> 111 </div> 112 </div> 113 <div class="sect3" lang="en" xml:lang="en"> 114 <div class="titlepage"> 115 <div> 116 <div> 117 <h4 class="title"><a id="id1666737"></a>app_malloc</h4> 118 </div> 119 </div> 120 </div> 121 <p> 122 The <span class="bold"><strong>app_malloc</strong></span> parameter is the 123 application-specified malloc function. 124 </p> 125 </div> 126 <div class="sect3" lang="en" xml:lang="en"> 127 <div class="titlepage"> 128 <div> 129 <div> 130 <h4 class="title"><a id="id1666857"></a>app_realloc</h4> 131 </div> 132 </div> 133 </div> 134 <p> 135 The <span class="bold"><strong>app_realloc</strong></span> parameter is the 136 application-specified realloc function. 137 </p> 138 </div> 139 <div class="sect3" lang="en" xml:lang="en"> 140 <div class="titlepage"> 141 <div> 142 <div> 143 <h4 class="title"><a id="id1666872"></a>app_free</h4> 144 </div> 145 </div> 146 </div> 147 <p> 148 The <span class="bold"><strong>app_free</strong></span> parameter is the 149 application-specified free function. 150 </p> 151 </div> 152 </div> 153 <div class="sect2" lang="en" xml:lang="en"> 154 <div class="titlepage"> 155 <div> 156 <div> 157 <h3 class="title"><a id="id1666887"></a>Errors</h3> 158 </div> 159 </div> 160 </div> 161 <p> 162 The <code class="methodname">DB_ENV->set_alloc()</code> <span> 163 <span> 164 method may fail and return one of the following non-zero errors: 165 </span> 166 167 </span> 168 </p> 169 <div class="sect3" lang="en" xml:lang="en"> 170 <div class="titlepage"> 171 <div> 172 <div> 173 <h4 class="title"><a id="id1666781"></a>EINVAL</h4> 174 </div> 175 </div> 176 </div> 177 <p> 178 If the method was called after <a class="xref" href="envopen.html" title="DB_ENV->open()">DB_ENV->open()</a> 179 was called; or if an invalid flag value or parameter was specified. 180 </p> 181 </div> 182 </div> 183 <div class="sect2" lang="en" xml:lang="en"> 184 <div class="titlepage"> 185 <div> 186 <div> 187 <h3 class="title"><a id="id1666745"></a>Class</h3> 188 </div> 189 </div> 190 </div> 191 <p> 192 <a class="link" href="env.html" title="Chapter��5.�� The DB_ENV Handle">DB_ENV</a> 193 </p> 194 </div> 195 <div class="sect2" lang="en" xml:lang="en"> 196 <div class="titlepage"> 197 <div> 198 <div> 199 <h3 class="title"><a id="id1666732"></a>See Also</h3> 200 </div> 201 </div> 202 </div> 203 <p> 204 <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a> 205 </p> 206 </div> 207 </div> 208 <div class="navfooter"> 209 <hr /> 210 <table width="100%" summary="Navigation footer"> 211 <tr> 212 <td width="40%" align="left"><a accesskey="p" href="envremove.html">Prev</a>��</td> 213 <td width="20%" align="center"> 214 <a accesskey="u" href="env.html">Up</a> 215 </td> 216 <td width="40%" align="right">��<a accesskey="n" href="envset_app_dispatch.html">Next</a></td> 217 </tr> 218 <tr> 219 <td width="40%" align="left" valign="top">DB_ENV->remove()��</td> 220 <td width="20%" align="center"> 221 <a accesskey="h" href="index.html">Home</a> 222 </td> 223 <td width="40%" align="right" valign="top">��DB_ENV->set_app_dispatch()</td> 224 </tr> 225 </table> 226 </div> 227 </body> 228</html> 229