Nebula
|
#include <stringbuffer.h>
Global string buffer for the StringAtom system.
This is where all raw strings for the StringAtom system are stored. If enabled, the StringBuffer can grow, but it may never shrink. Once a string is in the string buffer, it cannot be removed. String data is simply appended to the last position, strings are separated by a 0-terminator-byte. A string is guaranteed never to move in memory. Several threads can have simultaneous read-access to the string buffer, even while an AddString() is in progress by another thread. Only if several threads attempt to call AddString() a lock must be taken.
NOTE: NOT thread-safe! Usually, GlobalStringAtomTable cares about thread-safety for the global string buffer.
Public Member Functions | |
StringBuffer () | |
constructor | |
~StringBuffer () | |
destructor | |
void | Setup (SizeT size) |
setup the string buffer with size in bytes | |
void | Discard () |
discard the string buffer | |
bool | IsValid () const |
return true if string buffer has been setup | |
const char * | AddString (const char *str) |
add a string to the end of the string buffer, return pointer to string | |
const char * | NextString (const char *prev) |
DEBUG: return next string in string buffer. | |
SizeT | GetNumChunks () const |
DEBUG: get number of allocated chunks. | |
Private Member Functions | |
void | AllocNewChunk () |
allocate a new chunk | |
Private Attributes | |
Util::Array< char * > | chunks |
SizeT | chunkSize |
char * | curPointer |
Util::StringBuffer::StringBuffer | ( | ) |
constructor
Util::StringBuffer::~StringBuffer | ( | ) |
destructor
const char * Util::StringBuffer::AddString | ( | const char * | str | ) |
add a string to the end of the string buffer, return pointer to string
Copies a string to the end of the string buffer, returns pointer to copied string.
|
private |
allocate a new chunk
void Util::StringBuffer::Discard | ( | ) |
discard the string buffer
|
inline |
DEBUG: get number of allocated chunks.
|
inline |
return true if string buffer has been setup
const char * Util::StringBuffer::NextString | ( | const char * | prev | ) |
DEBUG: return next string in string buffer.
void Util::StringBuffer::Setup | ( | SizeT | size | ) |
setup the string buffer with size in bytes
NOTE: this method must be called before any threads are spawned.
|
private |
|
private |
|
private |