chiark / gitweb /
Support for resource pools, based on the Apache model.
[mLib] / man / arena.3
CommitLineData
cededfbe 1.\" -*-nroff-*-
2.TH arena 3 "3 June 2000" mLib
3.SH "NAME"
4arena \- control of memory allocation
5.\" @arena_global
6.\" @arena_stdlib
7.\" @arena_fakemalloc
8.\" @a_alloc
9.\" @a_realloc
10.\" @a_free
11.\" @A_ALLOC
12.\" @A_REALLOC
13.\" @A_FREE
14.SH "SYNOPSIS"
15.nf
16.B "#include <mLib/arena.h>"
17
18.BI "arena *arena_global;"
19.BI "arena arena_stdlib;"
20
21.BI "void *arena_fakerealloc(arena *" a ", void *" p ", size_t " sz );
22
23.BI "void *a_alloc(arena *" a ", size_t " sz );
24.BI "void *a_realloc(arena *" a ", void *" p ", size_t " sz );
25.BI "void a_free(arena *" a );
26
27.BI "void *A_ALLOC(arena *" a ", size_t " sz );
28.BI "void *A_REALLOC(arena *" a ", void *" p ", size_t " sz );
29.BI "void A_FREE(arena *" a );
30.fi
31.SH "DESCRIPTION"
32An
33.I arena
34is a place from which blocks of memory may be allocated and freed. The
35basic
36.B mLib
37library provides a single standard arena,
38.BR arena_stdlib ,
39which uses the usual
40.BR malloc (3)
41and
42.BR free (3)
43calls. The global variable
44.B arena_global
45is a pointer to a `current' arena, which is a good choice to use if
46you can't think of anything better.
47.PP
48The macros
49.BR A_ALLOC ,
50.B A_REALLOC
51and
52.B A_FREE
53behave like the standard C functions
54.BR malloc (3),
55.BR realloc (3)
56and
57.BR free (3),
58allocating, resizing and releasing blocks from a given arena. There are
59function-call equivalents with lower-case names too. For a more
60convenient interface to memory allocation, see
61.BR alloc (3).
62.PP
63.SS "Defining new arenas"
64An
65.B arena
66is a structure containing a single member,
67.BR ops ,
68which is a pointer to a structure of type
69.BR arena_ops .
70The
71.B arena
72structure may be followed in memory by data which is used by the arena's
73manager to maintain its state.
74.PP
75The
76.B arena_ops
77table contains function pointers which are called to perform various
78memory allocation tasks:
79.TP
80.BI "void *(*" alloc ")(arena *" a ", size_t " sz );
81Allocates a block of memory, of at least
82.I sz
83bytes in size, appropriately aligned, and returns its address.
84.TP
85.BI "void *(*" realloc ")(arena *" a ", void *" p ", size_t " sz );
86Resizes the block pointed to by
87.IR p ,
88so that it is at least
89.I sz
90bytes long. You can use
91.B arena_fakerealloc
92here, to fake resizing by allocating, copying and freeing, if your arena
93doesn't make doing something more efficient easy.
94.TP
95.BI "void (*" free ")(arena *" a ", void *" p );
96Frees the block pointed to by
97.IR p .
98.TP
99.BI "void (*" purge ")(arena *" a );
100Frees all blocks in the arena. Used when the arena is being destroyed.
101.PP
102The behaviour of the
103.IR alloc ,
104.I realloc
105and
106.I free
107calls with respect to null pointers and zero-sized blocks is as
108specified by the ANSI C standard.
109.SH "SEE ALSO"
110.BR alloc (3),
111.BR mLib (3).
112.SH AUTHOR
113Mark Wooding, <mdw@nsict.org>