1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>3. Nibble Memory</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="YAZ User's Guide and Reference"><link rel="up" href="tools.html" title="Chapter 9. Supporting Tools"><link rel="prev" href="tools.oid.html" title="2. Object Identifiers"><link rel="next" href="tools.log.html" title="4. Log"></head><body><link rel="stylesheet" type="text/css" href="common/style1.css"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3. Nibble Memory</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="tools.oid.html">Prev</a> </td><th width="60%" align="center">Chapter 9. Supporting Tools</th><td width="20%" align="right"> <a accesskey="n" href="tools.log.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="tools.nmem"></a>3. Nibble Memory</h2></div></div></div><p>
2 Sometimes when you need to allocate and construct a large,
3 interconnected complex of structures, it can be a bit of a pain to
4 release the associated memory again. For the structures describing the
5 Z39.50 PDUs and related structures, it is convenient to use the
6 memory-management system of the <acronym class="acronym">ODR</acronym> subsystem (see
7 <a class="xref" href="odr.use.html" title="2. Using ODR">Section 2, “Using ODR”</a>). However, in some circumstances
8 where you might otherwise benefit from using a simple nibble memory
9 management system, it may be impractical to use
10 <code class="function">odr_malloc()</code> and <code class="function">odr_reset()</code>.
11 For this purpose, the memory manager which also supports the <acronym class="acronym">ODR</acronym>
12 streams is made available in the NMEM module. The external interface
13 to this module is given in the <code class="filename">nmem.h</code> file.
15 The following prototypes are given:
16 </p><pre class="screen">
17 NMEM nmem_create(void);
18 void nmem_destroy(NMEM n);
19 void *nmem_malloc(NMEM n, int size);
20 void nmem_reset(NMEM n);
21 int nmem_total(NMEM n);
25 The <code class="function">nmem_create()</code> function returns a pointer to a
26 memory control handle, which can be released again by
27 <code class="function">nmem_destroy()</code> when no longer needed.
28 The function <code class="function">nmem_malloc()</code> allocates a block of
29 memory of the requested size. A call to <code class="function">nmem_reset()</code>
30 or <code class="function">nmem_destroy()</code> will release all memory allocated
31 on the handle since it was created (or since the last call to
32 <code class="function">nmem_reset()</code>. The function
33 <code class="function">nmem_total()</code> returns the number of bytes currently
34 allocated on the handle.
36 The nibble memory pool is shared amongst threads. POSIX
37 mutex'es and WIN32 Critical sections are introduced to keep the
38 module thread safe. Function <code class="function">nmem_init()</code>
39 initializes the nibble memory library and it is called automatically
40 the first time the <code class="literal">YAZ.DLL</code> is loaded. YAZ uses
41 function <code class="function">DllMain</code> to achieve this. You should
42 <span class="emphasis"><em>not</em></span> call <code class="function">nmem_init</code> or
43 <code class="function">nmem_exit</code> unless you're absolute sure what
44 you're doing. Note that in previous YAZ versions you'd have to call
45 <code class="function">nmem_init</code> yourself.
46 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tools.oid.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tools.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="tools.log.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2. Object Identifiers </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 4. Log</td></tr></table></div></body></html>