circularbuffer: Circular Buffer Example

This example demonstrates the how to use the circular buffer classes CCirBuf and CCirBuffer.


This example application shows how to construct and make use of circular buffers containing integers, objects of user defined classes and objects of an R class.


Click on the following link to download the example: circularbuffer .zip

Click browse to view the example code.

class summary

CCirBuffer CCirBuf

Design and implementation

Class diagram:

Figure: Circular buffers example class diagram

The example creates a circular buffer of integers using CCirBuffer::Put() to add elements and CCirBuffer::Get() to remove an element. To demonstrate the circular nature of the buffer, the example:

  • adds four elements until the buffer is full,

  • tries to adds another element to the buffer, which fails with a buffer full error message,

  • removes elements 1 and 2 from the buffer, leaving elements 3 and 4,

  • adds two new elements (5 and 6) to the buffer,

  • removes all elements (3, 4, 5 and 6) from the buffer.

Similar steps are performed using CCirBuf to add (CCirBuf::Add()) and remove (CCirBuf::Remove()) user-defined objects, and objects of an R class to and from the buffer.

After removing R class objects from the circular buffer, they must be closed in order to release the resource held by the R Class objects.

Building and configuring

To build the example:

  • You can build the example from your IDE or the command line.

    If you use an IDE, import the bld.inf file of the example into your IDE, and use the build command of the IDE.

    If you use the command line, open a command prompt, and set the current directory to the source code directory of the example. You can then build the example with the SBSv1 build tools with the following commands:

    bldmake bldfiles

    abld build .

  • For the emulator, the example builds an executable called circularbuffer.exe in the epoc32\release\winscw\<udeb or urel>\ folder.

Running the example

The user is prompted to press a key in order to progress from one function to the next.