@@@ much mess, mostly manpages
[mLib] / struct / dspool.3.in
CommitLineData
b6b9d458 1.\" -*-nroff-*-
c4ccbbf9
MW
2.\"
3.\" Manual for string pools
4.\"
5.\" (c) 1999, 2001, 2005, 2009, 2023, 2024 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of the mLib utilities library.
11.\"
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.
16.\"
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.
21.\"
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,
25.\" USA.
26.
27.\"--------------------------------------------------------------------------
28.so ../defs.man \" @@@PRE@@@
29.
30.\"--------------------------------------------------------------------------
31.TH dspool 3mLib "20 June 1999" "Straylight/Edgeware" "mLib utilities library"
08da152e 32.\" @dspool_create
33.\" @dspool_destroy
34.\" @dspool_get
35.\" @dspool_put
c4ccbbf9 36.
08da152e 37.\" @DSGET
38.\" @DSPUT
c4ccbbf9
MW
39.
40.\"--------------------------------------------------------------------------
41.SH NAME
42dspool \- pools of preallocated dynamic strings
43.
44.\"--------------------------------------------------------------------------
b6b9d458 45.SH SYNOPSIS
c4ccbbf9 46.
b6b9d458 47.nf
d2a91066 48.B "#include <mLib/dspool.h>"
d056fbdf 49.PP
4729aa69 50.B "typedef struct { ...\& } dspool;"
d056fbdf 51.PP
b6b9d458 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 );
d056fbdf 56.PP
d2a91066 57.BI "void DSGET(dspool *" p ", " d );
b6b9d458 58.BI "void DSPUT(dspool *" p ", dstr *" d );
59.fi
c4ccbbf9
MW
60.
61.\"--------------------------------------------------------------------------
b6b9d458 62.SH DESCRIPTION
c4ccbbf9 63.
b6b9d458 64A dynamic string pool maintains a collection of `spare' dynamic
65strings. Some pieces of code require high turnover of strings, and
66allocating and freeing them entails a large amount of overhead. A
67dynamic string pool keeps a list of dynamic strings which have been
68allocated but are not currently in use.
69.PP
70A pool is created by the function
71.BR dspool_create .
72It is passed the address of a pool structure
73.I p
74and the initial size
d2a91066 75.I isz
b6b9d458 76to allocate for new dynamic strings obtained from the pool. A newly
77created pool contains no strings. Once a pool is no longer required,
78the function
79.B dspool_destroy
80will release all the strings in the pool, such that the pool can safely
81be thrown away.
82.PP
83A string is obtained from a pool by calling
84.BR dspool_get .
85If the pool is empty, a new string is allocated; otherwise a string is
86chosen from those currently in the pool.
87.PP
88A string is returned to the pool by the
89.B dspool_put
90function. It is passed the address of a pool and the address of a
91string to return. The string must have been allocated from
92.I some
93dynamic string pool, although it's not actually necessary to return it
94to the pool from which it was allocated.
95.PP
96The macro call
97.VS
98DSGET(p, d);
99.VE
100is equivalent to the assignment
101.VS
102d = dspool_get(p);
103.VE
104(except that it's probably quicker). The macro
105.B DSPUT
106is entirely equivalent to the function
107.B dspool_put
108except for improved performance.
c4ccbbf9
MW
109.
110.\"--------------------------------------------------------------------------
b6b9d458 111.SH CAVEATS
c4ccbbf9 112.
b6b9d458 113The string pool allocator requires the suballocator (see
08da152e 114.BR sub (3)
b6b9d458 115for details). You must ensure that
116.B sub_init
117is called before any strings are allocated from a string pool.
c4ccbbf9
MW
118.
119.\"--------------------------------------------------------------------------
b6b9d458 120.SH SEE ALSO
c4ccbbf9 121.
08da152e 122.BR dstr (3),
123.BR sub (3),
124.BR mLib (3).
c4ccbbf9
MW
125.
126.\"--------------------------------------------------------------------------
b6b9d458 127.SH AUTHOR
c4ccbbf9 128.
9b5ac6ff 129Mark Wooding, <mdw@distorted.org.uk>
c4ccbbf9
MW
130.
131.\"----- That's all, folks --------------------------------------------------