14 .TH sub 3mLib "8 May 1999" mLib
16 sub \- efficient allocation and freeing of small blocks
19 .B "#include <mLib/sub.h>"
21 .B "void sub_init(void);"
22 .BI "void *sub_alloc(size_t " sz );
23 .BI "void sub_free(void *" p ", size_t " sz );
25 .BI "void *CREATE(" type );
26 .BI "void DESTROY(" type " *" p );
31 collection of functions and macros implement an efficient allocator for
32 small blocks of known sizes. Free blocks of the same size are linked
33 together in list, making freeing and allocation fast. The `free'
34 operation requires the block size as an argument, so there's no data
35 overhead for an allocated block. The system takes advantage of this by
36 allocating big chunks from the underlying system (actually via
38 q.v.) and splitting the chunks into smaller blocks of the right size, so
39 the space and time overhead from the underlying allocator is divided
46 bytes. If there isn't enough memory to allocate the block, the
53 function frees a block allocated by
55 You must know the size of the block in advance. Note that
57 never gives memory back to the underlying allocator. Free sub-blocks
58 are just made available to later calls of
61 Don't try to pass blocks allocated by
65 similarly, don't try to pass blocks allocated by
71 If you do, you'll get what you deserve.
77 are intended to provide a slightly more natural interface to
80 mystruct *p = sub_alloc(sizeof(mystruct));
84 mystruct p = CREATE(mystruct);
86 Similarly, the block can be freed by saying
90 rather than the more cubersome
92 sub_free(p, sizeof(*p));
96 must be called before any of the other
100 Mark Wooding, <mdw@nsict.org>