14 .TH dspool 3mLib "20 June 1999" mLib
16 dspool \- pools of preallocated dynamic strings
19 .B "#include <mLib/dspool.h>
21 .BI "void dspool_create(dspool *" p ", size_t " isz );
22 .BI "void dspool_destroy(dspool *" p );
23 .BI "dstr *dspool_get(dspool *" p );
24 .BI "void dspool_put(dspool *" p ", dstr *" d );
26 .BI "dstr *DSGET(dspool *" p ", d );
27 .BI "void DSPUT(dspool *" p ", dstr *" d );
30 A dynamic string pool maintains a collection of `spare' dynamic
31 strings. Some pieces of code require high turnover of strings, and
32 allocating and freeing them entails a large amount of overhead. A
33 dynamic string pool keeps a list of dynamic strings which have been
34 allocated but are not currently in use.
36 A pool is created by the function
38 It is passed the address of a pool structure
42 to allocate for new dynamic strings obtained from the pool. A newly
43 created pool contains no strings. Once a pool is no longer required,
46 will release all the strings in the pool, such that the pool can safely
49 A string is obtained from a pool by calling
51 If the pool is empty, a new string is allocated; otherwise a string is
52 chosen from those currently in the pool.
54 A string is returned to the pool by the
56 function. It is passed the address of a pool and the address of a
57 string to return. The string must have been allocated from
59 dynamic string pool, although it's not actually necessary to return it
60 to the pool from which it was allocated.
66 is equivalent to the assignment
70 (except that it's probably quicker). The macro
72 is entirely equivalent to the function
74 except for improved performance.
76 The string pool allocator requires the suballocator (see
78 for details). You must ensure that
80 is called before any strings are allocated from a string pool.
85 Mark Wooding, <mdw@nsict.org>