Implementing the QIODevice read stream as a RingBuffer
-
hi,
i want to implement QIODevice read stream as RingBuffer.
can any one help me with this. -
yes shoyeb there is a way to do it
u will have to impliment a ring buffer class for this
check out the code below it should not pose any problem in migrating it to qt.
all the best@
/* This approach replaces the CircularBuffer 'end' field with the
'count' field and changes these functions: */void cbInit(CircularBuffer *cb, int size) {
cb->size = size;
cb->start = 0;
cb->count = 0;
cb->elems = (ElemType *)calloc(cb->size, sizeof(ElemType));
}int cbIsFull(CircularBuffer *cb) {
return cb->count == cb->size; }int cbIsEmpty(CircularBuffer *cb) {
return cb->count == 0; }void cbWrite(CircularBuffer *cb, ElemType *elem) {
int end = (cb->start + cb->count) % cb->size;
cb->elems[end] = elem;
if (cb->count == cb->size)
cb->start = (cb->start + 1) % cb->size; / full, overwrite */
else
++ cb->count;
}void cbRead(CircularBuffer *cb, ElemType *elem) {
*elem = cb->elems[cb->start];
cb->start = (cb->start + 1) % cb->size;
-- cb->count;
}
@[EDIT: code formatting, please wrap in @-tags, Volker]
-
thanx batosai i will try that...