3 .\" Manual for configurable memory management
5 .\" (c) 2000, 2001, 2005, 2009, 2023, 2024 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the mLib utilities library.
12 .\" mLib is free software: you can redistribute it and/or modify it under
13 .\" the terms of the GNU Library General Public License as published by
14 .\" the Free Software Foundation; either version 2 of the License, or (at
15 .\" your option) any later version.
17 .\" mLib is distributed in the hope that it will be useful, but WITHOUT
18 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 .\" License for more details.
22 .\" You should have received a copy of the GNU Library General Public
23 .\" License along with mLib. If not, write to the Free Software
24 .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
30 .\"--------------------------------------------------------------------------
31 .TH arena 3mLib "3 June 2000" "Straylight/Edgeware" "mLib utilities library"
42 .\"--------------------------------------------------------------------------
44 arena \- control of memory allocation
46 .\"--------------------------------------------------------------------------
50 .B "#include <mLib/arena.h>"
54 .B " const struct arena_ops *ops";
58 .BI " void *(*alloc)(arena *" a ", size_t " sz );
59 .BI " void *(*realloc)(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
60 .BI " void *(*free)(arena *" a ", void *" p );
61 .BI " void *(*purge)(arena *" a );
64 .BI "arena *arena_global;"
65 .BI "arena arena_stdlib;"
67 .ta \w'\fBvoid *arena_fakerealloc('u
68 .BI "void *arena_fakerealloc(arena *" a ", void *" p ,
69 .BI " size_t " sz ", size_t " osz );
71 .BI "void *a_alloc(arena *" a ", size_t " sz );
72 .BI "void *a_realloc(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
73 .BI "void a_free(arena *" a );
75 .BI "void *A_ALLOC(arena *" a ", size_t " sz );
76 .BI "void *A_REALLOC(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
77 .BI "void A_FREE(arena *" a );
80 .\"--------------------------------------------------------------------------
85 is a place from which blocks of memory may be allocated and freed. The
88 library provides a single standard arena,
94 calls. The global variable
96 is a pointer to a `current' arena, which is a good choice to use if
97 you can't think of anything better.
104 behave like the standard C functions
109 allocating, resizing and releasing blocks from a given arena. There are
110 function-call equivalents with lower-case names too. For a more
111 convenient interface to memory allocation, see
117 function has an extra argument
119 specifying the old size of the block. This is for the benefit of arena
120 handlers which can't easily find the old block's size.
123 .SS "Defining new arenas"
126 is a structure containing a single member,
128 which is a pointer to a structure of type
132 structure may be followed in memory by data which is used by the arena's
133 manager to maintain its state.
137 table contains function pointers which are called to perform various
138 memory allocation tasks:
140 .BI "void *(*alloc)(arena *" a ", size_t " sz );
141 Allocates a block of memory, of at least
143 bytes in size, appropriately aligned, and returns its address.
146 .BI "void *(*realloc)(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
148 Resizes the block pointed to by
152 interesting bytes in it,
153 so that it is at least
155 bytes long. You can use
157 here, to fake resizing by allocating, copying and freeing, if your arena
158 doesn't make doing something more efficient easy.
160 .BI "void (*free)(arena *" a ", void *" p );
161 Frees the block pointed to by
164 .BI "void (*purge)(arena *" a );
165 Frees all blocks in the arena. Used when the arena is being destroyed.
172 calls with respect to null pointers and zero-sized blocks is as
173 specified by the ANSI C standard.
175 .\"--------------------------------------------------------------------------
181 .\"--------------------------------------------------------------------------
184 Mark Wooding, <mdw@distorted.org.uk>
186 .\"----- That's all, folks --------------------------------------------------