2 * A simple growing buffer
4 * (c) 2004, Robert Spalek <robert@ucw.cz>
6 * Define the following macros:
8 * GBUF_TYPE data type of records stored in the buffer
9 * GBUF_PREFIX(x) add a name prefix to all global symbols
12 #define BUF_T GBUF_PREFIX(t)
22 GBUF_PREFIX(init)(BUF_T *b)
29 GBUF_PREFIX(done)(BUF_T *b)
38 GBUF_PREFIX(realloc)(BUF_T *b, uns len)
42 b->ptr = xrealloc(b->ptr, len * sizeof(GBUF_TYPE));
44 b->ptr = xmalloc(len * sizeof(GBUF_TYPE));
48 GBUF_PREFIX(grow)(BUF_T *b, uns len)
52 if (len < 2*b->len) // to ensure logarithmic cost
54 GBUF_PREFIX(realloc)(b, len);