Next: Locking, Previous: Crash Tolerance, Up: Top [Contents][Index]
GDBM
supports the ability to set certain options on an already
open database.
Sets an option on the database or returns the value of an option.
The parameters are:
The pointer returned by gdbm_open
.
The option to be set or retrieved.
A pointer to the value to which option will be set or where to place the option value (depending on the option).
The length of the data pointed to by value.
The return value will be -1
upon failure, or 0
upon
success. The global variable gdbm_errno
will be set upon failure.
The valid options are:
Set the size of the internal bucket cache. The value should
point to a size_t
holding the desired cache size, or the
constant GDBM_CACHE_AUTO
, to adjust the cache size
automatically.
By default, a newly open database is configured to dynamically accommodate the cache size to the number of index buckets in the database file. This provides for the best performance.
If another value is set, it is adjusted to the nearest larger power of two.
Use this option if you wish to limit the memory usage at the expense of performance. If you chose to do so, please bear in mind that cache becomes effective when its size is greater then 2/3 of the number of index bucket counts in the database. The best performance results are achieved when cache size equals the number of buckets. For example:
size_t bn; gdbm_bucket_count (dbf, &bn); ret = gdbm_setopt (dbf, GDBM_SETCACHESIZE, &bn, sizeof (bn));
To request the automatically adjustable cache size, use the constant
GDBM_CACHE_AUTO
:
size_t bn = GDBM_CACHE_AUTO; ret = gdbm_setopt (dbf, GDBM_SETCACHESIZE, &bn, sizeof (bn));
Return the actual size of the internal bucket cache. The value
should point to a size_t
variable, where the size will be
stored.
Controls whether the cache size will be adjusted automatically as
needed. The value should point to an integer: TRUE
to
enable automatic cache adjustment and FALSE
to disable it.
The following two calls are equivalent:
int t = TRUE; gdbm_setopt (dbf, GDBM_SETCACHEAUTO, &t, sizeof (t)); size_t n = GDBM_CACHE_AUTO; gdbm_setopt (dbf, GDBM_SETCACHESIZE, &n, sizeof (n));
Return the state of the automatic cache size adjustment. The
value should point to an integer which, upon successful return,
will have the value TRUE
if the automatic cache size adjustment
is enabled and FALSE
otherwise.
Return the flags describing the state of the database. The value should
point to an int
variable where to store the flags. On success,
its value will be similar to the flags used when opening the database
(see gdbm_open), except that it will reflect the current state
(which may have been altered by another calls to gdbm_setopt
).
Return the database format. The value should point to an
int
variable. Upon successful return, it will be set to
‘0’ if the database is in standard format and GDBM_NUMSYNC
if it is in extended format. See Database format.
Returns the directory depth: the number of initial (most significant)
bits in hash value that are interpreted as index to the directory. The
actual directory size can be computed as 1 << value
.
The value argument should point to an int
.
Returns the bucket capacity: maximum number of keys per bucket
(int
).
Enable or disable the fast writes mode, i.e. writes without
subsequent synchronization. The value should point
to an integer: TRUE
to enable fast mode, and FALSE
to
disable it.
This option is retained for compatibility with previous versions of
GDBM
. Its effect is the reverse of GDBM_SETSYNCMODE
.
Turn on or off file system synchronization operations. This
setting defaults to off. The value should point
to an integer: TRUE
to turn synchronization on, and FALSE
to
turn it off.
Note, that this option is a reverse of GDBM_FASTMODE
,
i.e. calling GDBM_SETSYNCMODE
with TRUE
has the same effect
as calling GDBM_FASTMODE
with FALSE
.
The GDBM_SYNCMODE
option is provided for compatibility with
earlier versions.
Return the current synchronization status. The value should
point to an int
where the status will be stored.
NOTICE: This feature is still under study.
Set central free block pool to either on or off. The default is off,
which is how previous versions of GDBM
handled free blocks. If
set, this option causes all subsequent free blocks to be placed in the
global pool, allowing (in theory) more file space to be reused
more quickly. The value should point to an integer: TRUE
to
turn central block pool on, and FALSE
to turn it off.
The GDBM_CENTFREE
option is provided for compatibility with
earlier versions.
NOTICE: This feature is still under study.
Set free block merging to either on or off. The default is off, which
is how previous versions of GDBM
handled free blocks. If set,
this option causes adjacent free blocks to be merged. This can become
a CPU expensive process with time, though, especially if
used in conjunction with GDBM_CENTFREE. The value should point
to an integer: TRUE
to turn free block merging on, and FALSE
to
turn it off.
Return the current status of free block merging. The value should
point to an int
where the status will be stored.
Sets maximum size of a memory mapped region. The value should
point to a value of type size_t
, unsigned long
or
unsigned
. The actual value is rounded to the nearest page
boundary (the page size is obtained from
sysconf(_SC_PAGESIZE)
).
Return the maximum size of a memory mapped region. The value should
point to a value of type size_t
where to return the data.
Enable or disable memory mapping mode. The value should point
to an integer: TRUE
to enable memory mapping or FALSE
to
disable it.
Check whether memory mapping is enabled. The value should point to an integer where to return the status.
Return the name of the database disk file. The value should
point to a variable of type char**
. A pointer to the newly
allocated copy of the file name will be placed there. The caller is
responsible for freeing this memory when no longer needed. For
example:
char *name; if (gdbm_setopt (dbf, GDBM_GETDBNAME, &name, sizeof (name))) { fprintf (stderr, "gdbm_setopt failed: %s\n", gdbm_strerror (gdbm_errno)); } else { printf ("database name: %s\n", name); free (name); }
Return the block size in bytes. The value should point to int
.
Next: Locking, Previous: Crash Tolerance, Up: Top [Contents][Index]