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::set_cachesize()</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="db.html" title="Chapter 2. The Db Handle" /> 11 <link rel="prev" href="dbset_bt_prefix.html" title="Db::set_bt_prefix()" /> 12 <link rel="next" href="dbset_create_dir.html" title="Db::set_create_dir()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Db::set_cachesize()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="dbset_bt_prefix.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 2. 23 The Db Handle 24 </th> 25 <td width="20%" align="right"> <a accesskey="n" href="dbset_create_dir.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="dbset_cachesize"></a>Db::set_cachesize()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db_cxx.h> 39 40int 41Db::set_cachesize(u_int32_t gbytes, u_int32_t bytes, int ncache); </pre> 42 <p> 43 Set the size of the shared memory buffer pool -- that is, the cache. 44 The cache should be the size of the normal working data set of the 45 application, with some small amount of additional memory for unusual 46 situations. (Note: the working set is not the same as the number of 47 pages accessed simultaneously, and is usually much larger.) 48 </p> 49 <p> 50 The default cache size is 256KB, and may not be specified as less than 51 20KB. Any cache size less than 500MB is automatically increased by 52 25% to account for buffer pool overhead; cache sizes larger than 500MB 53 are used as specified. The maximum size of a single cache is 4GB on 54 32-bit systems and 10TB on 64-bit systems. (All sizes are in 55 powers-of-two, that is, 256KB is 2^18 not 256,000.) For information on 56 tuning the Berkeley DB cache size, see <a href="../../programmer_reference/general_am_conf.html#am_conf_cachesize" class="olink">Selecting a cache size</a>. 57 </p> 58 <p> 59 It is possible to specify caches to Berkeley DB large enough they 60 cannot be allocated contiguously on some architectures. For example, 61 some releases of Solaris limit the amount of memory that may be 62 allocated contiguously by a process. If <span class="bold"><strong>ncache</strong></span> is 0 or 1, the cache will be allocated 63 contiguously in memory. If it is greater than 1, the cache will be 64 split across <span class="bold"><strong>ncache</strong></span> separate regions, 65 where the <span class="bold"><strong>region size</strong></span> is equal to the 66 initial cache size divided by <span class="bold"><strong>ncache</strong></span>. 67 </p> 68 <p> 69 Because databases opened within Berkeley DB environments use the cache 70 specified to the environment, it is an error to attempt to set a cache 71 in a database created within an environment. 72 </p> 73 <p> 74 The <code class="methodname">Db::set_cachesize()</code> method may not be called after the 75 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> method is called. 76 </p> 77 <p> 78 The <code class="methodname">Db::set_cachesize()</code> <span> 79 80 <span> 81 method either returns a non-zero error value or throws an 82 exception that encapsulates a non-zero error value on 83 failure, and returns 0 on success. 84 </span> 85 </span> 86 </p> 87 <div class="sect2" lang="en" xml:lang="en"> 88 <div class="titlepage"> 89 <div> 90 <div> 91 <h3 class="title"><a id="id1644827"></a>Parameters</h3> 92 </div> 93 </div> 94 </div> 95 <div class="sect3" lang="en" xml:lang="en"> 96 <div class="titlepage"> 97 <div> 98 <div> 99 <h4 class="title"><a id="id1644832"></a>bytes</h4> 100 </div> 101 </div> 102 </div> 103 <p> 104 The size of the cache is set to <span class="bold"><strong>gbytes</strong></span> gigabytes plus <span class="bold"><strong>bytes</strong></span>. 105 </p> 106 </div> 107 <div class="sect3" lang="en" xml:lang="en"> 108 <div class="titlepage"> 109 <div> 110 <div> 111 <h4 class="title"><a id="id1645071"></a>gbytes</h4> 112 </div> 113 </div> 114 </div> 115 <p> 116 The size of the cache is set to <span class="bold"><strong>gbytes</strong></span> gigabytes plus <span class="bold"><strong>bytes</strong></span>. 117 </p> 118 </div> 119 <div class="sect3" lang="en" xml:lang="en"> 120 <div class="titlepage"> 121 <div> 122 <div> 123 <h4 class="title"><a id="id1645083"></a>ncache</h4> 124 </div> 125 </div> 126 </div> 127 <p> 128 The <span class="bold"><strong>ncache</strong></span> parameter is the number of 129 caches to create. 130 </p> 131 </div> 132 </div> 133 <div class="sect2" lang="en" xml:lang="en"> 134 <div class="titlepage"> 135 <div> 136 <div> 137 <h3 class="title"><a id="id1645101"></a>Errors</h3> 138 </div> 139 </div> 140 </div> 141 <p> 142 The <code class="methodname">Db::set_cachesize()</code> <span> 143 144 <span> 145 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 146 exception, encapsulating one of the following non-zero errors, or return one 147 of the following non-zero errors: 148 </span> 149 </span> 150 </p> 151 <div class="sect3" lang="en" xml:lang="en"> 152 <div class="titlepage"> 153 <div> 154 <div> 155 <h4 class="title"><a id="id1644973"></a>EINVAL</h4> 156 </div> 157 </div> 158 </div> 159 <p> 160 If the specified cache size was impossibly small; the method was 161 called after <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> 162 was called; or if an invalid flag value or parameter was specified. 163 </p> 164 </div> 165 </div> 166 <div class="sect2" lang="en" xml:lang="en"> 167 <div class="titlepage"> 168 <div> 169 <div> 170 <h3 class="title"><a id="id1644974"></a>Class</h3> 171 </div> 172 </div> 173 </div> 174 <p> 175 <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> 176 </p> 177 </div> 178 <div class="sect2" lang="en" xml:lang="en"> 179 <div class="titlepage"> 180 <div> 181 <div> 182 <h3 class="title"><a id="id1645059"></a>See Also</h3> 183 </div> 184 </div> 185 </div> 186 <p> 187 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 188 </p> 189 </div> 190 </div> 191 <div class="navfooter"> 192 <hr /> 193 <table width="100%" summary="Navigation footer"> 194 <tr> 195 <td width="40%" align="left"><a accesskey="p" href="dbset_bt_prefix.html">Prev</a> </td> 196 <td width="20%" align="center"> 197 <a accesskey="u" href="db.html">Up</a> 198 </td> 199 <td width="40%" align="right"> <a accesskey="n" href="dbset_create_dir.html">Next</a></td> 200 </tr> 201 <tr> 202 <td width="40%" align="left" valign="top">Db::set_bt_prefix() </td> 203 <td width="20%" align="center"> 204 <a accesskey="h" href="index.html">Home</a> 205 </td> 206 <td width="40%" align="right" valign="top"> Db::set_create_dir()</td> 207 </tr> 208 </table> 209 </div> 210 </body> 211</html> 212