rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit db2ae57e3e03b5939fa17ab8fe6c7b951b12396d
parent 37ca5a5af6a6066ba12d98e9a8143cea10accd33
Author: vaplv <vaplv@free.fr>
Date:   Sat, 13 May 2017 15:01:41 +0200

Update the big_buffer init

The submitted bufsz means for the number of buffered data and not, as
previously, the size in bytes of the buffer in which the buffered data
were stored.

Diffstat:
Msrc/big_buffer.h | 13++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/big_buffer.h b/src/big_buffer.h @@ -176,12 +176,12 @@ BIGBUF_FUNC__(release)(struct BIGBUF__* bigbuf) static INLINE res_T BIGBUF_FUNC__(init) (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */ - const size_t bufsz, /* size in bytes of the buffered data */ + const size_t bufsz, /* # buffered data */ FILE* stream, /* May be NULL <=> internally manage the stream */ int mask, /* Combination of bigbuf_flag */ struct BIGBUF__* bigbuf) { - size_t bufsz_adjusted; + size_t size; res_T res = RES_OK; ASSERT(bigbuf); memset(bigbuf, 0, sizeof(struct BIGBUF__)); @@ -196,17 +196,16 @@ BIGBUF_FUNC__(init) } bigbuf->allocator = allocator ? allocator : &mem_default_allocator; - bigbuf->buf.capacity = bufsz / sizeof(BIGBUF_DATA); - bigbuf->buf.capacity = MMAX(bigbuf->buf.capacity, 1); - bufsz_adjusted = bigbuf->buf.capacity * sizeof(BIGBUF_DATA); + bigbuf->buf.capacity = bufsz; + size = bigbuf->buf.capacity * sizeof(BIGBUF_DATA); bigbuf->buf.data = MEM_ALLOC_ALIGNED - (bigbuf->allocator, bufsz_adjusted, BIGBUF_ALIGNMENT__); + (bigbuf->allocator, size, BIGBUF_ALIGNMENT__); if(!bigbuf->buf.data) { res = RES_MEM_ERR; goto error; } - memset(bigbuf->buf.data, 0, bufsz_adjusted); + memset(bigbuf->buf.data, 0, size); bigbuf->buf.size = 0; if(stream) {