Debian Codegraph @

html/alloc.html

raw
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html><head>
3 <title>liboop: oop_malloc(), oop_free()</title>
4 <link rel="stylesheet" type="text/css" href="style.css">
5 </head><body>
6
7 <h2>oop_malloc(), oop_free()</h2>
8
9 <pre>
10 #include &lt;oop.h&gt;
11
12 extern void *(*oop_malloc)(size_t len); /* <em>Allocate memory.</em> */
13 extern void *(*oop_realloc<a href="#note-realloc">*</a>)(void *ptr,size_t len); /* <em>Resize memory.</em> */
14 extern void (*oop_free)(void *ptr); /* <em>Free allocated memory.</em> */
15 </pre>
16
17 <h3>Arguments.</h3>
18
19 <dl>
20 <dt><b>size_t len</b>
21 <dd>Size, in bytes, of the memory block to allocate.<p>
22
23 <dt><b>void *ptr</b>
24 <dd>Pointer to memory block to free or reallocate.<p>
25 </dl>
26
27 <h3>Description.</h3>
28
29 These are global function pointers, initialized by default to the standard C
30 library functions <em>malloc</em>, <em>realloc</em>, and <em>free</em>.
31 Applications using liboop may reset these pointers to allocation and
32 deallocation routines with a compatible interface; libraries should use
33 these function pointers wherever possible to allocate and release memory.
34 These pointers are normally set before calling any liboop code; if they
35 are changed during operation, the new <em>oop_free</em> and
36 <em>oop_realloc</em> functions should be
37 capable of handling memory obtained with the old <em>oop_malloc</em>.
38
39 <dl>
40 <dt><b>oop_malloc</b>
41 <dd>This function allocates a block of memory of size <em>len</em> and returns
42 a pointer to the start of the block. If allocation fails, NULL is returned.<p>
43
44 <dt><b>oop_realloc</b><a href="#note-realloc">*</a>
45 <dd>This function resizes a block of memory at <em>ptr</em> to have the new
46 length <em>len</em>. If <em>ptr</em> is NULL, fresh memory is allocated.
47 If <em>len</em> is zero, memory is freed and NULL is returned.
48 If <em>ptr</em> is NULL and <em>len</em> is zero, nothing is done and NULL
49 is returned. If reallocation fails, NULL is returned.<p>
50
51 <dt><b>oop_free</b>
52 <dd>This function releases a block of memory, designated by <em>ptr</em>,
53 previously allocated by <em>oop_malloc</em>. Once released, the memory may
54 be immediately overwritten, and/or reused by subsequent calls to
55 <em>oop_malloc</em>.
56 </dl>
57
58 <hr>
59 <p><a name="note-realloc">*</a> <b>Compatibility note:</b> oop_realloc
60 is only available in version 0.7 or newer.</p>
61
62 <hr><a href="ref.html">liboop reference</a></body></html>