Hi, cRingBufferLinear beheaves strangely. The attached test program creates a cRingBufferLinear of size 100 and margin 10 an then tries to fill it completely, get everything and fill it again. I'd expect to be able to put 100 bytes inside but that doesn't work. It fills up to 89 (i.e. size-margin-1 does that make any sense?). After beeing depleted and refilled it doesn't allow Get() anymore: put 25 lost 0 put 25 lost 0 put 25 lost 0 put 14 lost 11 got 89 at 0x8077012 got 0 at (nil) put 25 lost 0 put 25 lost 0 put 25 lost 0 put 14 lost 11 put 0 lost 25 got 0 at (nil) Shouldn't the buffer fill up to 100? I'd expect 'margin' to only affect Get(), i.e. block it until the specified number of bytes is available. cu Ludwig -- (o_ Ludwig.Nussel@gmx.de //\ PGP Key ID: FF8135CE V_/_ ICQ: 52166811
#include "tools.h" #include "ringbuffer.h" cRingBufferLinear rb(100, 10, true); void putbuffer(int count) { uchar buf[25] = {0}; for(; count; --count) { int ret = rb.Put(buf, sizeof(buf)); printf("put %d lost %d\n", ret, sizeof(buf)-ret); } } void consumebuffer() { while(1) { int count = 0; uchar* p = rb.Get(count); printf("got %d at %p\n", count, p); if(!p) break; rb.Del(count); } } int main(void) { putbuffer(4); consumebuffer(); putbuffer(5); consumebuffer(); return 0; }
Attachment:
pgp00009.pgp
Description: PGP signature