You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
2 months ago
|
Growing buffers
|
||
|
===============
|
||
|
|
||
|
*This module is obsolete. Please use <<gary:,growing arrays>> instead.*
|
||
|
|
||
|
It is quite usual situation when you need an array of items and you
|
||
|
don not know how large it will be in the time you allocate it. Then
|
||
|
you need some kind of dynamically growing buffer.
|
||
|
|
||
|
- <<gbuf,Generic growing buffers>>
|
||
|
- <<bbuf,Growing buffers for byte-sized items>>
|
||
|
|
||
|
[[gbuf]]
|
||
|
Generic growing buffers
|
||
|
-----------------------
|
||
|
|
||
|
The generic buffers are in `ucw/gbuf.h`. They are <<generic:,generics
|
||
|
generated by preprocessor>>. To use them, you need to define:
|
||
|
|
||
|
- `GBUF_PREFIX(name)` -- the identifier generating macro.
|
||
|
- `GBUF_TYPE` -- the data type they operate with.
|
||
|
|
||
|
You may define `GBUF_TRACE(\...)` macro. If you do, it will be used to
|
||
|
log the growing of the buffer. The macro should act like printf() --
|
||
|
the first parameter will be format, the rest variables for it.
|
||
|
|
||
|
!!ucw/gbuf.h GBUF_PREFIX
|
||
|
|
||
|
[[bbuf]]
|
||
|
Growing buffers for byte-sized items
|
||
|
------------------------------------
|
||
|
|
||
|
It is often needed to allocate the buffer by bytes (if you handle some
|
||
|
anonymous data) or characters (strings of unknown length).
|
||
|
|
||
|
With the `ucw/bbuf.h` header, you get an instance of growing buffers
|
||
|
with type `byte` and prefix `bb_`. Aside from that, you get few
|
||
|
functions to manipulate strings in the buffers.
|
||
|
|
||
|
!!ucw/bbuf.h
|