chiark / gitweb /
Add a slew of manual pages.
[mLib] / man / dspool.3
CommitLineData
b6b9d458 1.\" -*-nroff-*-
2.de VS
3.sp 1
4.in +5n
5.ft B
6.nf
7..
8.de VE
9.ft R
10.in -5n
11.sp 1
12.fi
13..
14.TH dspool 3mLib "20 June 1999" mLib
15.SH NAME
16dspool \- pools of preallocated dynamic strings
17.SH SYNOPSIS
18.nf
19.B "#include <mLib/dspool.h>
20
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 );
25
26.BI "dstr *DSGET(dspool *" p ", d );
27.BI "void DSPUT(dspool *" p ", dstr *" d );
28.fi
29.SH DESCRIPTION
30A dynamic string pool maintains a collection of `spare' dynamic
31strings. Some pieces of code require high turnover of strings, and
32allocating and freeing them entails a large amount of overhead. A
33dynamic string pool keeps a list of dynamic strings which have been
34allocated but are not currently in use.
35.PP
36A pool is created by the function
37.BR dspool_create .
38It is passed the address of a pool structure
39.I p
40and the initial size
41.I izs
42to allocate for new dynamic strings obtained from the pool. A newly
43created pool contains no strings. Once a pool is no longer required,
44the function
45.B dspool_destroy
46will release all the strings in the pool, such that the pool can safely
47be thrown away.
48.PP
49A string is obtained from a pool by calling
50.BR dspool_get .
51If the pool is empty, a new string is allocated; otherwise a string is
52chosen from those currently in the pool.
53.PP
54A string is returned to the pool by the
55.B dspool_put
56function. It is passed the address of a pool and the address of a
57string to return. The string must have been allocated from
58.I some
59dynamic string pool, although it's not actually necessary to return it
60to the pool from which it was allocated.
61.PP
62The macro call
63.VS
64DSGET(p, d);
65.VE
66is equivalent to the assignment
67.VS
68d = dspool_get(p);
69.VE
70(except that it's probably quicker). The macro
71.B DSPUT
72is entirely equivalent to the function
73.B dspool_put
74except for improved performance.
75.SH CAVEATS
76The string pool allocator requires the suballocator (see
77.BR sub (3mLib)
78for details). You must ensure that
79.B sub_init
80is called before any strings are allocated from a string pool.
81.SH SEE ALSO
82.BR dstr (3mLib),
83.BR sub (3mLib).
84.SH AUTHOR
85Mark Wooding, <mdw@nsict.org>