Debian Codegraph @

docs/api_reference/CXX/envset_alloc.html

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