3
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
4
<!--All rights reserved.-->
5
<!--See the file LICENSE for redistribution information.-->
8
<title>Berkeley DB: Db.set_cachesize</title>
9
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
10
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
13
<a name="2"><!--meow--></a>
14
<table width="100%"><tr valign=top>
16
<h1>Db.set_cachesize</h1>
19
<a href="../api_java/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
24
import com.sleepycat.db.*;
26
public void set_cachesize(int gbytes, int bytes, int ncache)
30
<p>Set the size of the shared memory buffer pool -- that is, the cache --
31
to <b>gbytes</b> gigabytes plus <b>bytes</b>. The cache should be
32
the size of the normal working data set of the application, with some
33
small amount of additional memory for unusual situations. (Note: the
34
working set is not the same as the number of pages accessed
35
simultaneously, and should be quite a bit larger!)
36
<p>The default cache size is 256KB, and may not be specified as less than
37
20KB. Any cache size less than 500MB is automatically increased by 25%
38
to account for buffer pool overhead; cache sizes larger than 500MB are
39
used as specified. The current maximum size of a single cache is 4GB.
40
For information on tuning the Berkeley DB cache size, see
41
<a href="../ref/am_conf/cachesize.html">Selecting a cache size</a>.
42
<p>It is possible to specify caches to Berkeley DB that are large enough so that
43
they cannot be allocated contiguously on some architectures. For
44
example, some releases of Solaris limit the amount of memory that may
45
be allocated contiguously by a process. If <b>ncache</b> is 0 or 1,
46
the cache will be allocated contiguously in memory. If it is greater
47
than 1, the cache will be broken up into <b>ncache</b> equally sized,
48
separate pieces of memory.
49
<p>Because databases opened within Berkeley DB environments use the cache
50
specified to the environment, it is an error to attempt to set a cache
51
in a database created within an environment.
52
<p>The Db.set_cachesize interface may not be called after the <a href="../api_java/db_open.html">Db.open</a>
54
<p>The Db.set_cachesize method throws an exception that encapsulates a non-zero error value on
56
<p>The database environment's cache size may also be set using the environment's
57
<b>DB_CONFIG</b> file. The syntax of the entry in that file is a
58
single line with the string "set_cachesize", one or more whitespace characters,
59
and the three arguments specified to this interface, separated by whitespace
60
characters, for example, "set_cachesize 1 500 2". Because the <b>DB_CONFIG</b> file is read when the database
61
environment is opened, it will silently overrule configuration done
64
<p>The Db.set_cachesize method may fail and throw an exception encapsulating a non-zero error for the following conditions:
66
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
67
<p>The specified cache size was impossibly small.
68
<p>Called in a database environment.
70
<a href="../api_java/db_open.html">Db.open</a>
73
<p>The Db.set_cachesize method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods.
74
If a catastrophic error has occurred, the Db.set_cachesize method may fail and
75
throw a <a href="../api_java/runrec_class.html">DbRunRecoveryException</a>,
76
in which case all subsequent Berkeley DB calls will fail in the same way.
78
<a href="../api_java/db_class.html">Db</a>
80
<a href="../api_java/db_list.html">Databases and Related Methods</a>
82
<table width="100%"><tr><td><br></td><td align=right>
83
<a href="../api_java/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
85
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>