Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Quasi-standard library for byte arrays (http://www.velocityreviews.com/forums/t754959-quasi-standard-library-for-byte-arrays.html)

Florian Weimer 10-17-2011 08:55 AM

Quasi-standard library for byte arrays
 
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.

jacob navia 10-17-2011 09:20 AM

Re: Quasi-standard library for byte arrays
 
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


All times are GMT. The time now is 04:42 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.