![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |
SFXRingBuffer is the class that represents a ring buffer.
A ring buffer is a chunk of memory arranged in the circular manner. The read pointer and write pointer advance clockwisely.
When data is written onto the buffer, the write pointer will advance. Until the last written position through the write pointer, data can be read through the read pointer.
The read pointer cannot go beyond the write pointer.
Example 14.10. Method to use the SFXRingBuffer class
Byte data1[] = {'1', '2', '3', '4', '5', '6', '7', '8'};
Byte data2[] = {'9', 'a', 'b', 'c', 'd', 'e'};
SFXRingBuffer ring;
SFXBuffer buffer;
// set size of ring buffer to 12 bytes
ring.Allocate(12);
// write 8-bytes data
ring.Write(data1, sizeof(data1));
// reserve buffer for reading
buffer.SetSize(4);
// read 4 bytes
ring.Read(&buffer); // buffer = "1234"
// write 6-bytes data
ring.Write(data2, sizeof(data2));
// reserve buffer for reading
buffer.SetSize(10);
// read 10 bytes
ring.Read(&buffer); // buffer = "56789abcde"
|
Copyright (C) 2002 - 2008 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|