14 .TH dspool 3 "20 June 1999" "Straylight/Edgeware" "mLib utilities library"
16 dspool \- pools of preallocated dynamic strings
27 .B "#include <mLib/dspool.h>"
29 .B "typedef struct { ...\& } dspool;"
31 .BI "void dspool_create(dspool *" p ", size_t " isz );
32 .BI "void dspool_destroy(dspool *" p );
33 .BI "dstr *dspool_get(dspool *" p );
34 .BI "void dspool_put(dspool *" p ", dstr *" d );
36 .BI "void DSGET(dspool *" p ", " d );
37 .BI "void DSPUT(dspool *" p ", dstr *" d );
40 A dynamic string pool maintains a collection of `spare' dynamic
41 strings. Some pieces of code require high turnover of strings, and
42 allocating and freeing them entails a large amount of overhead. A
43 dynamic string pool keeps a list of dynamic strings which have been
44 allocated but are not currently in use.
46 A pool is created by the function
48 It is passed the address of a pool structure
52 to allocate for new dynamic strings obtained from the pool. A newly
53 created pool contains no strings. Once a pool is no longer required,
56 will release all the strings in the pool, such that the pool can safely
59 A string is obtained from a pool by calling
61 If the pool is empty, a new string is allocated; otherwise a string is
62 chosen from those currently in the pool.
64 A string is returned to the pool by the
66 function. It is passed the address of a pool and the address of a
67 string to return. The string must have been allocated from
69 dynamic string pool, although it's not actually necessary to return it
70 to the pool from which it was allocated.
76 is equivalent to the assignment
80 (except that it's probably quicker). The macro
82 is entirely equivalent to the function
84 except for improved performance.
86 The string pool allocator requires the suballocator (see
88 for details). You must ensure that
90 is called before any strings are allocated from a string pool.
96 Mark Wooding, <mdw@distorted.org.uk>