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->bstop = b->buffer = mp_expand(FB_POOL(b)->mp);
26 b->bufend = b->buffer + mp_avail(FB_POOL(b)->mp);
27 b->bptr = b->buffer + len;
32 fbpool_start(struct fbpool *b, struct mempool *mp, uns init_size)
35 b->fb.buffer = b->fb.bstop = b->fb.bptr = mp_start(mp, init_size);
36 b->fb.bufend = b->fb.buffer + mp_avail(mp);
40 fbpool_end(struct fbpool *b)
42 return mp_end(b->mp, b->fb.bptr);
46 fbpool_init(struct fbpool *b)
49 b->fb.name = "<fbpool>";
50 b->fb.spout = fbpool_spout;
51 b->fb.can_overwrite_buffer = 1;
65 fbpool_start(&fb, mp, 16);
66 for (uns i = 0; i < 1024; i++)
67 bprintf(&fb.fb, "<hello>");
72 for (uns i = 0; i < 1024; i++)
73 if (memcmp(p + i * 7, "<hello>", 7))