Fennel: ByteBuffer Class Reference (original) (raw)
ByteBuffer allows access to an array of buffers as a single memory space. More...
#include <[ByteBuffer.h](ByteBuffer%5F8h-source.html)>
| Public Member Functions | |
|---|---|
| ByteBuffer () | |
| void | init (boost::shared_array< PBuffer > ppBuffers, uint nBuffers, uint bufSize) |
| Provides storage for the virtual byte buffer. | |
| uint | getSize () |
| Returns the size of the buffer, in bytes. | |
| UnsignedByte | getByte (uint pos) |
| Returns the byte at pos. | |
| void | setByte (uint pos, UnsignedByte b) |
| Sets byte at pos. | |
| void | mergeByte (uint pos, UnsignedByte b) |
| Merges (OR's) byte at pos. | |
| PBuffer | getMem (uint pos, uint &size) |
| Returns a pointer to contiguous memory. | |
| void | setMem (uint pos, UnsignedByte value, uint len) |
| Initializes a run of bytes in the buffer. | |
| void | copyMem (uint pos, PConstBuffer mem, uint len) |
| Copies a run of bytes into the buffer. | |
| void | mergeMem (uint pos, PConstBuffer mem, uint len) |
| Merges (OR's) a run of bytes into the buffer; similar to memmerge. | |
| Private Member Functions | |
| uint | getI (uint pos) |
| Returns which buffer to use to access pos. | |
| uint | getJ (uint pos) |
| Returns offset within buffer to use to access pos. | |
| Static Private Member Functions | |
| static void | memmerge (PBuffer dest, PConstBuffer src, uint len) |
| Merges (OR's) one buffer into another. | |
| Private Attributes | |
| boost::shared_array< PBuffer > | ppBuffers |
| uint | nBuffers |
| uint | bufferSize |
| uint | bufferMask |
| uint | bufferShift |
Detailed Description
ByteBuffer allows access to an array of buffers as a single memory space.
It allows for optimization with direct memory access. It has an interface for accessing one byte at a time (less overhead), and an interface for accessing runs of bytes (more overhead, but processes one memory chunk at a time). The methods setMem and copyMem are similar to memset and memcpy.
This class neither allocates nor deallocates memory, except through shared pointers. As usual, indexes are zero-based.
Version:
Id
//open/dev/fennel/common/ByteBuffer.h#9
Definition at line 48 of file ByteBuffer.h.
Constructor & Destructor Documentation
| ByteBuffer::ByteBuffer | ( | | ) | [explicit] | | ---------------------- | - | | - | ------------ |
Member Function Documentation
| uint ByteBuffer::getI | ( | uint | pos | ) | [inline, private] |
|---|
Returns which buffer to use to access pos.
Definition at line 59 of file ByteBuffer.h.
| uint ByteBuffer::getJ | ( | uint | pos | ) | [inline, private] |
|---|
Returns offset within buffer to use to access pos.
Definition at line 69 of file ByteBuffer.h.
Merges (OR's) one buffer into another.
Definition at line 79 of file ByteBuffer.h.
Referenced by mergeMem().
00080 { 00081 PBuffer end = dest + len; 00082 while (dest < end) { 00083 *dest++ |= *src++; 00084 } 00085 }
| void ByteBuffer::init | ( | boost::shared_array< PBuffer > | ppBuffers, |
|---|---|---|---|
| uint | nBuffers, | ||
| uint | bufSize | ||
| ) |
| uint ByteBuffer::getSize | ( | | ) | | ------------------------------------------------------------------------------------- | - | | - |
Returns a pointer to contiguous memory.
Parameters:
| pos | memory position |
|---|---|
| size | returns size of the contiguous memory |
Definition at line 131 of file ByteBuffer.h.
Referenced by copyMem(), mergeMem(), and setMem().
Initializes a run of bytes in the buffer.
Definition at line 59 of file ByteBuffer.cpp.
References getMem(), and getSize().
00060 { 00061 assert(pos + len <= getSize()); 00062 uint current = pos; 00063 uint remaining = len; 00064 00065 while (remaining > 0) { 00066 uint chunkLen; 00067 PBuffer mem = getMem(current, chunkLen); 00068 if (chunkLen >= remaining) { 00069 memset(mem, value, remaining); 00070 break; 00071 } 00072 memset(mem, value, chunkLen); 00073 current += chunkLen; 00074 remaining -= chunkLen; 00075 } 00076 }
Copies a run of bytes into the buffer.
Definition at line 78 of file ByteBuffer.cpp.
References getMem(), and getSize().
00079 { 00080 assert(pos + len <= getSize()); 00081 uint current = pos; 00082 PConstBuffer currentData = data; 00083 uint remaining = len; 00084 00085 while (remaining > 0) { 00086 uint chunkLen; 00087 PBuffer mem = getMem(current, chunkLen); 00088 if (chunkLen >= remaining) { 00089 memcpy(mem, currentData, remaining); 00090 break; 00091 } 00092 memcpy(mem, currentData, chunkLen); 00093 current += chunkLen; 00094 currentData += chunkLen; 00095 remaining -= chunkLen; 00096 } 00097 }
Merges (OR's) a run of bytes into the buffer; similar to memmerge.
Definition at line 99 of file ByteBuffer.cpp.
References getMem(), getSize(), and memmerge().
00100 { 00101 assert(pos + len <= getSize()); 00102 uint current = pos; 00103 PConstBuffer currentData = data; 00104 uint remaining = len; 00105 00106 while (remaining > 0) { 00107 uint chunkLen; 00108 PBuffer mem = getMem(current, chunkLen); 00109 if (chunkLen >= remaining) { 00110 memmerge(mem, currentData, remaining); 00111 break; 00112 } 00113 memmerge(mem, currentData, chunkLen); 00114 current += chunkLen; 00115 currentData += chunkLen; 00116 remaining -= chunkLen; 00117 } 00118 }
Member Data Documentation
The documentation for this class was generated from the following files:
- /home/pub/open/dev/fennel/common/ByteBuffer.h
- /home/pub/open/dev/fennel/common/ByteBuffer.cpp
