2 .TH arena 3 "3 June 2000" "Straylight/Edgeware" "mLib utilities library"
4 arena \- control of memory allocation
16 .B "#include <mLib/arena.h>"
20 .B " const struct arena_ops *ops";
24 .BI " void *(*alloc)(arena *" a ", size_t " sz );
25 .BI " void *(*realloc)(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
26 .BI " void *(*free)(arena *" a ", void *" p );
27 .BI " void *(*purge)(arena *" a );
30 .BI "arena *arena_global;"
31 .BI "arena arena_stdlib;"
33 .ta \w'\fBvoid *arena_fakerealloc('u
34 .BI "void *arena_fakerealloc(arena *" a ", void *" p ,
35 .BI " size_t " sz ", size_t " osz );
37 .BI "void *a_alloc(arena *" a ", size_t " sz );
38 .BI "void *a_realloc(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
39 .BI "void a_free(arena *" a );
41 .BI "void *A_ALLOC(arena *" a ", size_t " sz );
42 .BI "void *A_REALLOC(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
43 .BI "void A_FREE(arena *" a );
48 is a place from which blocks of memory may be allocated and freed. The
51 library provides a single standard arena,
57 calls. The global variable
59 is a pointer to a `current' arena, which is a good choice to use if
60 you can't think of anything better.
67 behave like the standard C functions
72 allocating, resizing and releasing blocks from a given arena. There are
73 function-call equivalents with lower-case names too. For a more
74 convenient interface to memory allocation, see
80 function has an extra argument
82 specifying the old size of the block. This is for the benefit of arena
83 handlers which can't easily find the old block's size.
85 .SS "Defining new arenas"
88 is a structure containing a single member,
90 which is a pointer to a structure of type
94 structure may be followed in memory by data which is used by the arena's
95 manager to maintain its state.
99 table contains function pointers which are called to perform various
100 memory allocation tasks:
102 .BI "void *(*alloc)(arena *" a ", size_t " sz );
103 Allocates a block of memory, of at least
105 bytes in size, appropriately aligned, and returns its address.
108 .BI "void *(*realloc)(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
110 Resizes the block pointed to by
114 interesting bytes in it,
115 so that it is at least
117 bytes long. You can use
119 here, to fake resizing by allocating, copying and freeing, if your arena
120 doesn't make doing something more efficient easy.
122 .BI "void (*free)(arena *" a ", void *" p );
123 Frees the block pointed to by
126 .BI "void (*purge)(arena *" a );
127 Frees all blocks in the arena. Used when the arena is being destroyed.
134 calls with respect to null pointers and zero-sized blocks is as
135 specified by the ANSI C standard.
140 Mark Wooding, <mdw@distorted.org.uk>