The Nebula Device 3: Util::StringBuffer Class Reference

The Nebula Device 3

Util::StringBuffer Class Reference

#include <stringbuffer.h>


Detailed Description

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.

(C) 2009 Radon Labs GmbH

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.

Member Function Documentation

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.

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.