3 cfa37a7b 2004-04-10 devnull binalloc, bingrow, binfree \- grouped memory allocation
4 cfa37a7b 2004-04-10 devnull .SH SYNOPSIS
5 cfa37a7b 2004-04-10 devnull .B #include <u.h>
7 cfa37a7b 2004-04-10 devnull .B #include <libc.h>
9 cfa37a7b 2004-04-10 devnull .B #include <bin.h>
11 cfa37a7b 2004-04-10 devnull .ta \w'\fLvoid* 'u
14 cfa37a7b 2004-04-10 devnull typedef struct Bin Bin;
17 cfa37a7b 2004-04-10 devnull void *binalloc(Bin **bp, ulong size, int clr);
20 cfa37a7b 2004-04-10 devnull void *bingrow(Bin **bp, void *op, ulong osize,
23 c8b6342d 2005-01-13 devnull ulong size, int clr);
26 cfa37a7b 2004-04-10 devnull void binfree(Bin **bp);
27 cfa37a7b 2004-04-10 devnull .SH DESCRIPTION
28 cfa37a7b 2004-04-10 devnull These routines provide simple grouped memory allocation and deallocation.
29 cfa37a7b 2004-04-10 devnull Items allocated with
30 cfa37a7b 2004-04-10 devnull .I binalloc
31 cfa37a7b 2004-04-10 devnull are added to the
33 cfa37a7b 2004-04-10 devnull pointed to by
35 cfa37a7b 2004-04-10 devnull All items in a bin may be freed with one call to
36 cfa37a7b 2004-04-10 devnull .IR binfree ;
37 cfa37a7b 2004-04-10 devnull there is no way to free a single item.
39 cfa37a7b 2004-04-10 devnull .I Binalloc
40 cfa37a7b 2004-04-10 devnull returns a pointer to a new block of at least
43 cfa37a7b 2004-04-10 devnull The block is suitably aligned for storage of any type of object.
44 cfa37a7b 2004-04-10 devnull No two active pointers from
45 cfa37a7b 2004-04-10 devnull .I binalloc
46 cfa37a7b 2004-04-10 devnull will have the same value.
48 cfa37a7b 2004-04-10 devnull .B binalloc(0)
49 cfa37a7b 2004-04-10 devnull returns a valid pointer rather than null.
52 cfa37a7b 2004-04-10 devnull is non-zero, the allocated memory is set to 0;
53 cfa37a7b 2004-04-10 devnull otherwise, the contents are undefined.
55 cfa37a7b 2004-04-10 devnull .I Bingrow
56 cfa37a7b 2004-04-10 devnull is used to extend the size of a block of memory returned by
57 cfa37a7b 2004-04-10 devnull .IR binalloc .
59 cfa37a7b 2004-04-10 devnull must point to the same bin group used to allocate the original block,
62 cfa37a7b 2004-04-10 devnull must be the last size used to allocate or grow the block.
63 cfa37a7b 2004-04-10 devnull A pointer to a block of at least
65 cfa37a7b 2004-04-10 devnull bytes is returned, with the same contents in the first
67 cfa37a7b 2004-04-10 devnull locations.
70 cfa37a7b 2004-04-10 devnull is non-zero, the remaining bytes are set to 0,
71 cfa37a7b 2004-04-10 devnull and are undefined otherwise.
75 cfa37a7b 2004-04-10 devnull .BR nil ,
78 cfa37a7b 2004-04-10 devnull are ignored, and the result is the same as calling
79 cfa37a7b 2004-04-10 devnull .IR binalloc .
81 cfa37a7b 2004-04-10 devnull .I Binalloc
83 cfa37a7b 2004-04-10 devnull .I bingrow
84 cfa37a7b 2004-04-10 devnull allocate large chunks of memory using
85 bf8a59fa 2004-04-11 devnull .IR malloc (3)
86 cfa37a7b 2004-04-10 devnull and return pieces of these chunks.
87 cfa37a7b 2004-04-10 devnull The chunks are
88 cfa37a7b 2004-04-10 devnull .IR free 'd
89 cfa37a7b 2004-04-10 devnull upon a call to
90 cfa37a7b 2004-04-10 devnull .IR binfree .
91 cfa37a7b 2004-04-10 devnull .SH SOURCE
92 c3674de4 2005-01-11 devnull .B \*9/src/libbin
93 cfa37a7b 2004-04-10 devnull .SH SEE ALSO
94 bf8a59fa 2004-04-11 devnull .IR malloc (3)
95 cfa37a7b 2004-04-10 devnull .SH DIAGNOSTICS
96 cfa37a7b 2004-04-10 devnull .I binalloc
98 cfa37a7b 2004-04-10 devnull .I bingrow
99 cfa37a7b 2004-04-10 devnull return 0 if there is no available memory.