File: alloc.html

package info (click to toggle)
liboop 1.0-8
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,664 kB
  • ctags: 492
  • sloc: sh: 7,970; ansic: 2,512; makefile: 136
file content (62 lines) | stat: -rw-r--r-- 2,432 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!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.html">liboop reference</a></body></html>