Nebula
Loading...
Searching...
No Matches
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.

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
 

Constructor & Destructor Documentation

◆ StringBuffer()

Util::StringBuffer::StringBuffer ( )

constructor

◆ ~StringBuffer()

Util::StringBuffer::~StringBuffer ( )

destructor

Member Function Documentation

◆ AddString()

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.

◆ AllocNewChunk()

void Util::StringBuffer::AllocNewChunk ( )
private

allocate a new chunk

◆ Discard()

void Util::StringBuffer::Discard ( )

discard the string buffer

◆ GetNumChunks()

SizeT Util::StringBuffer::GetNumChunks ( ) const
inline

DEBUG: get number of allocated chunks.

◆ IsValid()

bool Util::StringBuffer::IsValid ( ) const
inline

return true if string buffer has been setup

◆ NextString()

const char * Util::StringBuffer::NextString ( const char * prev)

DEBUG: return next string in string buffer.

◆ Setup()

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.

Member Data Documentation

◆ chunks

Util::Array<char*> Util::StringBuffer::chunks
private

◆ chunkSize

SizeT Util::StringBuffer::chunkSize
private

◆ curPointer

char* Util::StringBuffer::curPointer
private

The documentation for this class was generated from the following files: