2 * UCW Library -- Fast Buffered I/O on Memory Pools
4 * (c) 2007 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "ucw/mempool.h"
12 #include "ucw/fastbuf.h"
17 #define FB_POOL(f) ((struct fbpool *)(f)->is_fastbuf)
20 fbpool_spout(struct fastbuf *b)
22 if (b->bptr >= b->bufend)
24 uns len = b->bufend - b->buffer;
25 b->buffer = mp_expand(FB_POOL(b)->mp);
26 b->bufend = b->buffer + mp_avail(FB_POOL(b)->mp);
28 b->bptr = b->buffer + len;
33 fbpool_start(struct fbpool *b, struct mempool *mp, uns init_size)
36 b->fb.buffer = b->fb.bstop = b->fb.bptr = mp_start(mp, init_size);
37 b->fb.bufend = b->fb.buffer + mp_avail(mp);
41 fbpool_end(struct fbpool *b)
43 return mp_end(b->mp, b->fb.bptr);
47 fbpool_init(struct fbpool *b)
50 b->fb.name = "<fbpool>";
51 b->fb.spout = fbpool_spout;
52 b->fb.can_overwrite_buffer = 1;
66 fbpool_start(&fb, mp, 16);
67 for (uns i = 0; i < 1024; i++)
68 bprintf(&fb.fb, "<hello>");
73 for (uns i = 0; i < 1024; i++)
74 if (memcmp(p + i * 7, "<hello>", 7))