Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Blame | Last modification | View Log | RSS feed

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html><head>
<title>liboop: oop_malloc(), oop_free()</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head><body>

<h2>oop_malloc(), oop_free()</h2>

<pre>
#include &lt;oop.h&gt;

extern void *(*oop_malloc)(size_t len); /* <em>Allocate memory.</em> */
extern void *(*oop_realloc<a href="#note-realloc">*</a>)(void *ptr,size_t len); /* <em>Resize memory.</em> */
extern void (*oop_free)(void *ptr);     /* <em>Free allocated memory.</em> */
</pre>

<h3>Arguments.</h3>

<dl>
<dt><b>size_t len</b>
<dd>Size, in bytes, of the memory block to allocate.<p>

<dt><b>void *ptr</b>
<dd>Pointer to memory block to free or reallocate.<p>
</dl>

<h3>Description.</h3>

These are global function pointers, initialized by default to the standard C
library functions <em>malloc</em>, <em>realloc</em>, and <em>free</em>.  
Applications using liboop may reset these pointers to allocation and 
deallocation routines with a compatible interface; libraries should use 
these function pointers wherever possible to allocate and release memory.  
These pointers are normally set before calling any liboop code; if they 
are changed during operation, the new <em>oop_free</em> and 
<em>oop_realloc</em> functions should be 
capable of handling memory obtained with the old <em>oop_malloc</em>.

<dl>
<dt><b>oop_malloc</b>
<dd>This function allocates a block of memory of size <em>len</em> and returns
a pointer to the start of the block.  If allocation fails, NULL is returned.<p>

<dt><b>oop_realloc</b><a href="#note-realloc">*</a>
<dd>This function resizes a block of memory at <em>ptr</em> to have the new
length <em>len</em>.  If <em>ptr</em> is NULL, fresh memory is allocated.
If <em>len</em> is zero, memory is freed and NULL is returned.  
If <em>ptr</em> is NULL and <em>len</em> is zero, nothing is done and NULL
is returned.  If reallocation fails, NULL is returned.<p>

<dt><b>oop_free</b>
<dd>This function releases a block of memory, designated by <em>ptr</em>, 
previously allocated by <em>oop_malloc</em>.  Once released, the memory may
be immediately overwritten, and/or reused by subsequent calls to 
<em>oop_malloc</em>.
</dl>

<hr>
<p><a name="note-realloc">*</a> <b>Compatibility note:</b> oop_realloc
is only available in version 0.7 or newer.</p>

<hr><a href="ref">liboop reference</a></body></html>