3 .\" Manual for string pools
5 .\" (c) 1999, 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 dspool 3mLib "20 June 1999" "Straylight/Edgeware" "mLib utilities library"
40 .\"--------------------------------------------------------------------------
42 dspool \- pools of preallocated dynamic strings
44 .\"--------------------------------------------------------------------------
48 .B "#include <mLib/dspool.h>"
50 .B "typedef struct { ...\& } dspool;"
52 .BI "void dspool_create(dspool *" p ", size_t " isz );
53 .BI "void dspool_destroy(dspool *" p );
54 .BI "dstr *dspool_get(dspool *" p );
55 .BI "void dspool_put(dspool *" p ", dstr *" d );
57 .BI "void DSGET(dspool *" p ", " d );
58 .BI "void DSPUT(dspool *" p ", dstr *" d );
61 .\"--------------------------------------------------------------------------
64 A dynamic string pool maintains a collection of `spare' dynamic
65 strings. Some pieces of code require high turnover of strings, and
66 allocating and freeing them entails a large amount of overhead. A
67 dynamic string pool keeps a list of dynamic strings which have been
68 allocated but are not currently in use.
70 A pool is created by the function
72 It is passed the address of a pool structure
76 to allocate for new dynamic strings obtained from the pool. A newly
77 created pool contains no strings. Once a pool is no longer required,
80 will release all the strings in the pool, such that the pool can safely
83 A string is obtained from a pool by calling
85 If the pool is empty, a new string is allocated; otherwise a string is
86 chosen from those currently in the pool.
88 A string is returned to the pool by the
90 function. It is passed the address of a pool and the address of a
91 string to return. The string must have been allocated from
93 dynamic string pool, although it's not actually necessary to return it
94 to the pool from which it was allocated.
100 is equivalent to the assignment
104 (except that it's probably quicker). The macro
106 is entirely equivalent to the function
108 except for improved performance.
110 .\"--------------------------------------------------------------------------
113 The string pool allocator requires the suballocator (see
115 for details). You must ensure that
117 is called before any strings are allocated from a string pool.
119 .\"--------------------------------------------------------------------------
126 .\"--------------------------------------------------------------------------
129 Mark Wooding, <mdw@distorted.org.uk>
131 .\"----- That's all, folks --------------------------------------------------