blob: c888193f81c1e229fa77d18bdf377dd54234dcc3 [file] [log] [blame]
rsccfa37a72004-04-10 18:53:55 +00001.TH BIN 3
2.SH NAME
3binalloc, bingrow, binfree \- grouped memory allocation
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.br
9.B #include <bin.h>
10.PP
11.ta \w'\fLvoid* 'u
12.PP
13.B
14typedef struct Bin Bin;
15.PP
16.B
17void *binalloc(Bin **bp, ulong size, int clr);
18.PP
19.B
20void *bingrow(Bin **bp, void *op, ulong osize,
21.br
22.B
rscc8b63422005-01-13 04:49:19 +000023 ulong size, int clr);
rsccfa37a72004-04-10 18:53:55 +000024.PP
25.B
26void binfree(Bin **bp);
27.SH DESCRIPTION
28These routines provide simple grouped memory allocation and deallocation.
29Items allocated with
30.I binalloc
31are added to the
32.I Bin
33pointed to by
34.IR bp .
35All items in a bin may be freed with one call to
36.IR binfree ;
37there is no way to free a single item.
38.PP
39.I Binalloc
40returns a pointer to a new block of at least
41.I size
42bytes.
43The block is suitably aligned for storage of any type of object.
44No two active pointers from
45.I binalloc
46will have the same value.
47The call
48.B binalloc(0)
49returns a valid pointer rather than null.
50If
51.I clr
52is non-zero, the allocated memory is set to 0;
53otherwise, the contents are undefined.
54.PP
55.I Bingrow
56is used to extend the size of a block of memory returned by
57.IR binalloc .
58.I Bp
59must point to the same bin group used to allocate the original block,
60and
61.I osize
62must be the last size used to allocate or grow the block.
63A pointer to a block of at least
64.I size
65bytes is returned, with the same contents in the first
66.I osize
67locations.
68If
69.I clr
70is non-zero, the remaining bytes are set to 0,
71and are undefined otherwise.
72If
73.I op
74is
75.BR nil ,
76it and
77.I osize
78are ignored, and the result is the same as calling
79.IR binalloc .
80.PP
81.I Binalloc
82and
83.I bingrow
84allocate large chunks of memory using
rscbf8a59f2004-04-11 03:42:27 +000085.IR malloc (3)
rsccfa37a72004-04-10 18:53:55 +000086and return pieces of these chunks.
87The chunks are
88.IR free 'd
89upon a call to
90.IR binfree .
91.SH SOURCE
rscc3674de2005-01-11 17:37:33 +000092.B \*9/src/libbin
rsccfa37a72004-04-10 18:53:55 +000093.SH SEE ALSO
rscbf8a59f2004-04-11 03:42:27 +000094.IR malloc (3)
rsccfa37a72004-04-10 18:53:55 +000095.SH DIAGNOSTICS
96.I binalloc
97and
98.I bingrow
99return 0 if there is no available memory.