Quasi-standard library for byte arrays

F

Florian Weimer

Is there are widely-used library for dealing with variable-length byte
arrays (with pre-allocation and an exponential sizing policy)? Maybe
I've missed something over the years, and some quasi-standard has
emerged.
 
J

jacob navia

Le 17/10/11 10:55, Florian Weimer a écrit :
Is there are widely-used library for dealing with variable-length byte
arrays (with pre-allocation and an exponential sizing policy)? Maybe
I've missed something over the years, and some quasi-standard has
emerged.

The C containers library (ccl) offers auto-resizing byte buffers.

The source code can be downloaded from:

http://code.google.com/p/ccl/

Thge resizing strategy is as follows:

static int enlargeBuffer(StreamBuffer *b,size_t chunkSize)
{
char *p;
size_t newSiz;

if (chunkSize < b->Size/2)
newSiz = b->Size/2;
else newSiz = chunkSize;
p = b->Allocator->realloc(b->Data,b->Size+newSiz);
if (p == NULL)
return CONTAINER_ERROR_NOMEMORY;
b->Data = p;
b->Size += newSiz;
return 1;
}

You can customize it as you wish...

jacob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top