<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>DB_ENV->memp_register()</title> <link rel="stylesheet" href="apiReference.css" type="text/css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> <link rel="start" href="index.html" title="Berkeley DB C API Reference" /> <link rel="up" href="memp.html" title="Chapter 8. The DB_MPOOLFILE Handle" /> <link rel="prev" href="mempfcreate.html" title="DB_ENV->memp_fcreate()" /> <link rel="next" href="mempstat.html" title="DB_ENV->memp_stat()" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">DB_ENV->memp_register()</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="mempfcreate.html">Prev</a> </td> <th width="60%" align="center">Chapter 8. The DB_MPOOLFILE Handle </th> <td width="20%" align="right"> <a accesskey="n" href="mempstat.html">Next</a></td> </tr> </table> <hr /> </div> <div class="sect1" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h2 class="title" style="clear: both"><a id="mempregister"></a>DB_ENV->memp_register()</h2> </div> </div> </div> <pre class="programlisting">#include <db.h> int DB_ENV->memp_register(DB_ENV *env, int ftype, int (*pgin_fcn)(DB_ENV *env, db_pgno_t pgno, void *pgaddr, DBT *pgcookie), int (*pgout_fcn)(DB_ENV *env, db_pgno_t pgno, void *pgaddr, DBT *pgcookie)); </pre> <p> The <code class="methodname">DB_ENV->memp_register()</code> method registers page-in and page-out functions for files of type <span class="bold"><strong>ftype</strong></span> in the cache. </p> <p> If the <span class="bold"><strong>pgin_fcn</strong></span> function is non-NULL, it is called each time a page is read into the cache from a file of type <span class="bold"><strong>ftype</strong></span>, or a page is created for a file of type <span class="bold"><strong>ftype</strong></span> (see the DB_MPOOL_CREATE flag for the <a class="xref" href="mempfget.html" title="DB_MPOOLFILE->get()">DB_MPOOLFILE->get()</a> method). </p> <p> If the <span class="bold"><strong>pgout_fcn</strong></span> function is non-NULL, it is called each time a page is written to a file of type <span class="bold"><strong>ftype</strong></span>. </p> <p> The purpose of the <code class="methodname">DB_ENV->memp_register()</code> function is to support processing when pages are entered into, or flushed from, the cache. For example, this functionality might be used to do byte-endian conversion as pages are read from, or written to, the underlying file. </p> <p> A file type must be specified to make it possible for unrelated threads or processes that are sharing a cache, to evict each other's pages from the cache. During initialization, applications should call <code class="methodname">DB_ENV->memp_register()</code> for each type of file requiring input or output processing that will be sharing the underlying cache. (No registry is necessary for the standard Berkeley DB access method types because <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> registers them separately.) </p> <p> If a thread or process does not call <code class="methodname">DB_ENV->memp_register()</code> for a file type, it is impossible for it to evict pages for any file requiring input or output processing from the cache. For this reason, <code class="methodname">DB_ENV->memp_register()</code> should always be called by each application sharing a cache for each type of file included in the cache, regardless of whether or not the application itself uses files of that type. </p> <p> The <code class="methodname">DB_ENV->memp_register()</code> <span> <span> method returns a non-zero error value on failure and 0 on success. </span> </span> </p> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1686562"></a>Parameters</h3> </div> </div> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1686498"></a>ftype</h4> </div> </div> </div> <p> The <span class="bold"><strong>ftype</strong></span> parameter specifies the type of file for which the page-in and page-out functions will be called. </p> <p> The <span class="bold"><strong>ftype</strong></span> value for a file must be a non-zero positive number less than 128 (0 and negative numbers are reserved for internal use by the Berkeley DB library). </p> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1686550"></a>pgin_fcn, pgout_fcn</h4> </div> </div> </div> <p> The page-in and page-out functions. </p> <p> The <span class="bold"><strong>pgin_fcn</strong></span> and <span class="bold"><strong>pgout_fcn</strong></span> functions are called with a reference to the current database environment, the page number being read or written, a pointer to the page being read or written, and any parameter <span class="bold"><strong>pgcookie</strong></span> that was specified to the <a class="xref" href="mempset_pgcookie.html" title="DB_MPOOLFILE->set_pgcookie()">DB_MPOOLFILE->set_pgcookie()</a> method. </p> <p> The <span class="bold"><strong>pgin_fcn</strong></span> and <span class="bold"><strong>pgout_fcn</strong></span> functions should return 0 on success, and a non-zero value on failure, in which case the shared Berkeley DB library function calling it will also fail, returning that non-zero value. The non-zero value should be selected from values outside of the Berkeley DB library namespace. </p> </div> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1686563"></a>Class</h3> </div> </div> </div> <p> <a class="link" href="env.html" title="Chapter 5. The DB_ENV Handle">DB_ENV</a>, <a class="link" href="memp.html" title="Chapter 8. The DB_MPOOLFILE Handle">DB_MPOOLFILE</a> </p> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1686644"></a>See Also</h3> </div> </div> </div> <p> <a class="xref" href="memp.html#memplist" title="Memory Pools and Related Methods">Memory Pools and Related Methods</a> </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="mempfcreate.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="memp.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="mempstat.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">DB_ENV->memp_fcreate() </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> DB_ENV->memp_stat()</td> </tr> </table> </div> </body> </html>