|
|
1.1 root 1: .TH POOL 3+
2: .CT 2 datatype
3: .SH NAME
4: pool \- fast memory allocation
5: .SH SYNOPSIS
6: .nf
7: .B #include <Pool.h>
8: .PP
9: .ft L
10: struct Pool {
11: Pool(unsigned);
12: ~Pool();
13: void* alloc();
14: void free(void*)
15: };
16: .fi
17: .SH DESCRIPTION
18: .PP
19: Every
20: .L Pool
21: is a collection of
22: .IR elements ,
23: each of which is an array of bytes.
24: All elements of a pool
25: are the same size.
26: Pool functions are
27: .nr xx \w'\fIp\fL.free(\fIep\fL)\ '
28: .TP \n(xxu
29: .BI Pool( n )
30: Construct a pool whose elements are of size
31: .I n.
32: .TP
33: .IB p .alloc()
34: Allocate a new element in pool
35: .LR p .
36: Return a pointer to the element.
37: .TP
38: .IB p .free( ep )
39: Free the element of
40: .I p
41: pointed to by
42: .I ep.
43: The element must
44: have been allocated from
45: .I p.
46: .PP
47: Destroying a pool
48: frees all the memory occupied by its elements.
49: .PP
50: The memory in a pool element is aligned on
51: the same boundary as memory returned by
52: .IR malloc (3)
53: so that it may be used to contain an
54: object of any type.
55: In typical use, there would be one pool per class, with
56: the pool known only to the
57: .B new
58: and
59: .B delete
60: operators of that class.
61: .SS Performance
62: Pool memory is allocated in chunks that are typically
63: about 1,000 bytes each.
64: Once a chunk is allocated to a particular pool,
65: that chunk is only released when the pool itself
66: is destroyed.
67: .PP
68: Elements are allocated inline except when
69: a new chunk must be added to the pool.
70: Elements are always freed inline.
71: .SH EXAMPLES
72: .B #include <Pool.h>
73: .PP
74: .EX
75: struct Mytype {
76: static Pool mypool;
77: // constructors and members
78: void* operator new(unsigned) { return mypool.alloc(); }
79: void operator delete(void* p) { mypool.free(p); }
80: };
81: .EE
82: .PP
83: .B Pool Mytype::mypool(sizeof(Mytype));
84: .SH SEE ALSO
85: .IR malloc (3)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.