Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Implementing the QIODevice read stream as a RingBuffer
Forum Updated to NodeBB v4.3 + New Features

Implementing the QIODevice read stream as a RingBuffer

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shoyeb
    wrote on last edited by
    #1

    hi,

    i want to implement QIODevice read stream as RingBuffer.
    can any one help me with this.

    There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      batosai
      wrote on last edited by
      #2

      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]

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shoyeb
        wrote on last edited by
        #3

        thanx batosai i will try that...

        There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved