2 .TH arena 3 "3 June 2000" "Straylight/Edgeware" "mLib utilities library"
4 arena \- control of memory allocation
16 .B "#include <mLib/arena.h>"
18 .BI "arena *arena_global;"
19 .BI "arena arena_stdlib;"
21 .BI "void *arena_fakerealloc(arena *" a ", void *" p ,
22 .BI " size_t " sz ", size_t " osz );
24 .BI "void *a_alloc(arena *" a ", size_t " sz );
25 .BI "void *a_realloc(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
26 .BI "void a_free(arena *" a );
28 .BI "void *A_ALLOC(arena *" a ", size_t " sz );
29 .BI "void *A_REALLOC(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
30 .BI "void A_FREE(arena *" a );
35 is a place from which blocks of memory may be allocated and freed. The
38 library provides a single standard arena,
44 calls. The global variable
46 is a pointer to a `current' arena, which is a good choice to use if
47 you can't think of anything better.
54 behave like the standard C functions
59 allocating, resizing and releasing blocks from a given arena. There are
60 function-call equivalents with lower-case names too. For a more
61 convenient interface to memory allocation, see
67 function has an extra argument
69 specifying the old size of the block. This is for the benefit of arena
70 handlers which can't easily find the old block's size.
72 .SS "Defining new arenas"
75 is a structure containing a single member,
77 which is a pointer to a structure of type
81 structure may be followed in memory by data which is used by the arena's
82 manager to maintain its state.
86 table contains function pointers which are called to perform various
87 memory allocation tasks:
89 .BI "void *(*" alloc ")(arena *" a ", size_t " sz );
90 Allocates a block of memory, of at least
92 bytes in size, appropriately aligned, and returns its address.
95 .BI "void *(*" realloc ")(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
97 Resizes the block pointed to by
101 interesting bytes in it,
102 so that it is at least
104 bytes long. You can use
106 here, to fake resizing by allocating, copying and freeing, if your arena
107 doesn't make doing something more efficient easy.
109 .BI "void (*" free ")(arena *" a ", void *" p );
110 Frees the block pointed to by
113 .BI "void (*" purge ")(arena *" a );
114 Frees all blocks in the arena. Used when the arena is being destroyed.
121 calls with respect to null pointers and zero-sized blocks is as
122 specified by the ANSI C standard.
127 Mark Wooding, <mdw@distorted.org.uk>