]> mj.ucw.cz Git - moe.git/blob - ucw/doc/growbuf.txt
Merge branch 'layout'
[moe.git] / ucw / doc / growbuf.txt
1 Growing buffers
2 ===============
3
4 It is quite usual situation when you need an array of items and you
5 don not know how large it will be in the time you allocate it. Then
6 you need some kind of dynamically growing buffer.
7
8 You can either use <<mempool:gbuf,mempools>>, which has similar
9 functionality, or this module.
10
11 - <<gbuf,Generic growing buffers>>
12 - <<bbuf,Growing buffers for byte-sized items>>
13
14 [[gbuf]]
15 Generic growing buffers
16 -----------------------
17
18 The generic buffers are in `ucw/gbuf.h`. They are <<generic:,generics
19 generated by preprocessor>>. To use them, you need to define:
20
21 - `GBUF_PREFIX(name)` -- the identifier generating macro.
22 - `GBUF_TYPE` -- the data type they operate with.
23
24 You may define `GBUF_TRACE(\...)` macro. If you do, it will be used to
25 log the growing of the buffer. The macro should act like printf() --
26 the first parameter will be format, the rest variables for it.
27
28 !!ucw/gbuf.h GBUF_PREFIX
29
30 [[bbuf]]
31 Growing buffers for byte-sized items
32 ------------------------------------
33
34 It is often needed to allocate the buffer by bytes (if you handle some
35 anonymous data) or characters (strings of unknown length).
36
37 With the `ucw/bbuf.h` header, you get an instance of growing buffers
38 with type `byte` and prefix `bb_`. Aside from that, you get few
39 functions to manipulate strings in the buffers.
40
41 !!ucw/bbuf.h