Introduction
Downloads
Documentation
Tutorials
Pixie Lite
Forum

Home

DynamicBuffer Class Reference
[Containers]

Dynamic memory buffer. More...

List of all members.


Public Member Functions

 DynamicBuffer (unsigned int initialCapacity=1024)
 DynamicBuffer (const DynamicBuffer &dynamicBuffer)
const DynamicBufferoperator= (const DynamicBuffer &dynamicBuffer)
 ~DynamicBuffer ()
void Clear (bool releaseMemory=false)
unsigned int GetSize () const
void SetSize (unsigned int size)
unsigned int GetCapacity () const
void SetCapacity (unsigned int capacity)
unsigned int GetPosition () const
void SetPosition (unsigned int position)
unsigned int Write (const char *value, unsigned int count=1)
unsigned int Write (const short *value, unsigned int count=1)
unsigned int Write (const int *value, unsigned int count=1)
unsigned int Write (const long *value, unsigned int count=1)
unsigned int Write (const unsigned char *value, unsigned int count=1)
unsigned int Write (const unsigned short *value, unsigned int count=1)
unsigned int Write (const unsigned int *value, unsigned int count=1)
unsigned int Write (const unsigned long *value, unsigned int count=1)
unsigned int Write (const float *value, unsigned int count=1)
unsigned int Write (const double *value, unsigned int count=1)
unsigned int Write (const bool *value, unsigned int count=1)
unsigned int Read (char *value, unsigned int count=1)
unsigned int Read (short *value, unsigned int count=1)
unsigned int Read (int *value, unsigned int count=1)
unsigned int Read (long *value, unsigned int count=1)
unsigned int Read (unsigned char *value, unsigned int count=1)
unsigned int Read (unsigned short *value, unsigned int count=1)
unsigned int Read (unsigned int *value, unsigned int count=1)
unsigned int Read (unsigned long *value, unsigned int count=1)
unsigned int Read (float *value, unsigned int count=1)
unsigned int Read (double *value, unsigned int count=1)
unsigned int Read (bool *value, unsigned int count=1)
void * GetPointer () const

Detailed Description

Dynamic memory buffer.

Author:
Mattias Gustavsson
The dynamic memory buffer is useful when you want to work with a memory buffer and not have to worry about buffer overruns or allocating/freeing memory. The dynamic buffer handles all that by itself. It will dynamically grow the buffer when needed, and you can safely use the Read/Write methods to manipulate its content, much like you would a file, but with the speed that comes from using memory.

It is also possible to access the memory of the buffer directly, but that can be risky as no safety checks are carried out, which opens it up to possible buffer overrun problems.

Note that memory used by the buffer is not allocated until the first time data is written to it. If it is important to have the memory allocated when the buffer is created, just do Write/Clear to force the allocation.

Definition at line 28 of file DynamicBuffer.h.


Constructor & Destructor Documentation

DynamicBuffer::DynamicBuffer ( unsigned int  initialCapacity = 1024  ) 

Constructor

Parameters:
initialCapacity Maximum number of bytes the buffer can initially store. Will be doubled every time the available space is used up.

Definition at line 10 of file DynamicBuffer.cpp.

DynamicBuffer::DynamicBuffer ( const DynamicBuffer dynamicBuffer  ) 

Copy Constructor

Parameters:
dynamicBuffer Buffer to copy

Definition at line 36 of file DynamicBuffer.cpp.

DynamicBuffer::~DynamicBuffer (  ) 

Destructor

Definition at line 23 of file DynamicBuffer.cpp.


Member Function Documentation

const DynamicBuffer & DynamicBuffer::operator= ( const DynamicBuffer dynamicBuffer  ) 

Assignment operator

Returns:
The new buffer
Parameters:
dynamicBuffer Buffer to copy

Definition at line 61 of file DynamicBuffer.cpp.

void DynamicBuffer::Clear ( bool  releaseMemory = false  ) 

Removes all data from the buffer. Usually, when clearing a buffer, you know it to be quite likely that future use of the buffer will result in about the same amount of space being required, and that is the default behavior: the memory is being kept as it is, and only the members keeping track of how much of the buffer is used will be reset. A little care needs to be taken though, as this might result in a lot of memory just hanging around when it could be used for other things instead. If you know that you probably won't be using as much memory in future uses of the buffer, you should specify true for the releaseMemory parameter, which will result in all the memory allocated for the buffer to be released, and the buffer will be reset to its initial size.

Parameters:
releaseMemory If set to true, all memory used by the buffer will be released, and the size is reset to the initial value

Definition at line 96 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::GetSize (  )  const

Gets the current size of the buffer

Returns:
The size of the used part of the buffer, in bytes

Definition at line 120 of file DynamicBuffer.cpp.

void DynamicBuffer::SetSize ( unsigned int  size  ) 

Sets the current size of the buffer, in bytes

Parameters:
size The new size

Definition at line 128 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::GetCapacity (  )  const

Gets the maximum number of bytes that can currently be stored in the buffer before it has to be resized

Returns:
The current capacity of the buffer, in bytes

Definition at line 140 of file DynamicBuffer.cpp.

void DynamicBuffer::SetCapacity ( unsigned int  capacity  ) 

Sets the maximum number of bytes that can be stored in the buffer. If the new capacity is less than the current capacity, the capacity will remain at its current value.

Parameters:
capacity The new capacity

Definition at line 148 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::GetPosition (  )  const

Gets the current position for read/write operations on the buffer. This is the position at which the next subsequent read/write operation will be done.

Returns:
The current position in the buffer

Definition at line 170 of file DynamicBuffer.cpp.

void DynamicBuffer::SetPosition ( unsigned int  position  ) 

Sets the current position for read/write operations on the buffer. The next subsequent read/write operation will be performed at this position. Note that if the position is set to a value that is outside the currently used range of the buffer, the buffer will be resized on the next Write operation, if need be.

Parameters:
position The new position of the buffer

Definition at line 178 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const char *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of chars from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 186 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const short *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of shorts from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 191 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const int *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of ints from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 196 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const long *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of longs from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 201 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const unsigned char *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of unsigned chars from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 206 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const unsigned short *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of unsigned shorts from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 211 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const unsigned int *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of unsigned ints from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 216 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const unsigned long *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of unsigned longs from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 221 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const float *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of floats from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 226 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const double *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of doubles from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements
Parameters:
value Pointer to the first element to write
count Number of elements to write

Definition at line 231 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Write ( const bool *  value,
unsigned int  count = 1 
)

Writes data to the buffer. Will copy "count" number of bools from the memory location specified in the "value" pointer to the current write position of the buffer.

Returns:
The number of successfully written elements

Definition at line 236 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( char *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of chars from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 246 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( short *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of shorts from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 251 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( int *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of ints from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 256 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( long *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of longs from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 261 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( unsigned char *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of unsigned chars from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 266 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( unsigned short *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of unsigned shorts from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 271 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( unsigned int *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of unsigned ints from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 276 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( unsigned long *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of unsigned longs from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 281 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( float *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of floats from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 286 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( double *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of doubles from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 291 of file DynamicBuffer.cpp.

unsigned int DynamicBuffer::Read ( bool *  value,
unsigned int  count = 1 
)

Reads data from the buffer. Will copy "count" number of bools from the current read position of the buffer to the memory location specified in the "value" pointer

Returns:
The number of elements that where successfully read
Parameters:
value Pointer to the first element to read data into
count Number of elements to read

Definition at line 296 of file DynamicBuffer.cpp.

void * DynamicBuffer::GetPointer (  )  const

Used to retrieve a raw pointer to the actual memory that holds the buffer data. Use this carefully, because no checks for memory overwrites or such will be done. Most of the time, the normal Read/Write methods should be used.

Definition at line 304 of file DynamicBuffer.cpp.



Pixie University and the Pixie Game Engine is created and managed by Mattias Gustavsson.
Reproduction/republishing of any material on this site without permission is strictly prohibited.