1<!--$Id: db_set_cachesize.so,v 10.21 2002/08/18 21:15:53 bostic Exp $--> 2<!--$Id: env_set_cachesize.so,v 10.51 2007/07/06 00:22:52 mjc Exp $--> 3<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 4<!--See the file LICENSE for redistribution information.--> 5<html> 6<head> 7<title>Berkeley DB: Db::set_cachesize</title> 8<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 9<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 10</head> 11<body bgcolor=white> 12<table width="100%"><tr valign=top> 13<td> 14<b>Db::set_cachesize</b> 15</td> 16<td align=right> 17<a href="/api_cxx/api_core.html"><img src="/images/api.gif" alt="API"></a> 18<a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a></td> 19</tr></table> 20<hr size=1 noshade> 21<tt> 22<b><pre> 23#include <db_cxx.h> 24<p> 25int 26Db::set_cachesize(u_int32_t gbytes, u_int32_t bytes, int ncache); 27int 28Db::get_cachesize(u_int32_t *gbytesp, u_int32_t *bytesp, int *ncachep); 29</pre></b> 30<hr size=1 noshade> 31<b>Description: Db::set_cachesize</b> 32<p>Set the size of the shared memory buffer pool -- that is, the cache. 33The cache should be the size of the normal working data set of the 34application, with some small amount of additional memory for unusual 35situations. (Note: the working set is not the same as the number of 36pages accessed simultaneously, and is usually much larger.)</p> 37<p>The default cache size is 256KB, and may not be specified as less than 3820KB. Any cache size less than 500MB is automatically increased by 25% 39to account for buffer pool overhead; cache sizes larger than 500MB are 40used as specified. The maximum size of a single cache is 4GB on 32-bit 41systems and 10TB on 64-bit systems. (All sizes are in powers-of-two, 42that is, 256KB is 2^18 not 256,000.) For information on tuning the Berkeley DB 43cache size, see <a href="/ref/am_conf/cachesize.html">Selecting a 44cache size</a>.</p> 45<p>It is possible to specify caches to Berkeley DB large enough they cannot be 46allocated contiguously on some architectures. For example, some 47releases of Solaris limit the amount of memory that may be allocated 48contiguously by a process. If <b>ncache</b> is 0 or 1, the cache will 49be allocated contiguously in memory. If it is greater than 1, the cache 50will be split across <b>ncache</b> separate regions, where the 51<b>region size</b> is equal to the initial cache size divided by 52<b>ncache</b>.</p> 53<p>Because databases opened within Berkeley DB environments use the cache 54specified to the environment, it is an error to attempt to set a cache 55in a database created within an environment.</p> 56<p>The Db::set_cachesize method may not be called after the <a href="/api_cxx/db_open.html">Db::open</a> method is called. 57</p> 58<p>The Db::set_cachesize method 59either returns a non-zero error value 60or throws an exception that encapsulates a non-zero error value on 61failure, and returns 0 on success. 62</p> 63<b>Parameters</b> <br> 64 <b>bytes</b><ul compact><li>The size of the cache is set to <b>gbytes</b> gigabytes plus <b>bytes</b>.</ul> 65 <b>gbytes</b><ul compact><li>The size of the cache is set to <b>gbytes</b> gigabytes plus <b>bytes</b>.</ul> 66 <b>ncache</b><ul compact><li>The <b>ncache</b> parameter is the number of caches to create.</ul> 67<br> 68<br><b>Errors</b> 69<p>The Db::set_cachesize method 70may fail and throw 71<a href="/api_cxx/except_class.html">DbException</a>, 72encapsulating one of the following non-zero errors, or return one of 73the following non-zero errors:</p> 74<br> 75<b>EINVAL</b><ul compact><li>If the specified cache size was impossibly small; 76the method was called after 77<a href="/api_cxx/db_open.html">Db::open</a> was called; or if an 78invalid flag value or parameter was specified.</ul> 79<br> 80<hr size=1 noshade> 81<b>Description: Db::get_cachesize</b> 82<p>The Db::get_cachesize method returns the current size and composition of the 83cache.</p> 84<p>The Db::get_cachesize method may be called at any time during the life of the 85application.</p> 86<p>The Db::get_cachesize method 87either returns a non-zero error value 88or throws an exception that encapsulates a non-zero error value on 89failure, and returns 0 on success. 90</p> 91<b>Parameters</b> <br> 92 <b>bytesp</b><ul compact><li>The <b>bytesp</b> parameter references memory into which 93 the additional bytes of memory in the cache is copied.</ul> 94 <b>gbytesp</b><ul compact><li>The <b>gbytesp</b> parameter references memory into which 95 the gigabytes of memory in the cache is copied.</ul> 96 <b>ncachep</b><ul compact><li>The <b>ncachep</b> parameter references memory into which 97 the number of caches is copied.</ul> 98<br> 99<hr size=1 noshade> 100<br><b>Class</b> 101<a href="/api_cxx/db_class.html">Db</a> 102<br><b>See Also</b> 103<a href="/api_cxx/db_list.html">Databases and Related Methods</a> 104</tt> 105<table width="100%"><tr><td><br></td><td align=right> 106<a href="/api_cxx/api_core.html"><img src="/images/api.gif" alt="API"></a><a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a> 107</td></tr></table> 108<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 109</body> 110</html> 111