#include <avir.h>
Public Member Functions | |
CBuffer (const capint aCapacity, const int aAlignment=0) | |
CBuffer (const CBuffer &Source) | |
void | alloc (const capint aCapacity, const int aAlignment=0) |
void | forceCapacity (const capint NewCapacity) |
void | free () |
capint | getCapacity () const |
void | increaseCapacity (const capint NewCapacity, const bool DoDataCopy=true) |
operator T * () const | |
CBuffer & | operator= (const CBuffer &Source) |
void | truncateCapacity (const capint NewCapacity) |
void | updateCapacity (const capint ReqCapacity) |
Memory buffer class for element array storage, with capacity tracking.
Allows easier handling of memory blocks allocation and automatic deallocation for arrays (buffers) consisting of elements of specified class. Tracks buffer's capacity in "int" variable; unsuitable for allocation of very large memory blocks (with more than 2 billion elements).
This class manages memory space only - it does not perform element class construction (initialization) operations. Buffer's required memory address alignment specification is supported.
Uses standard library to allocate and deallocate memory.
T | Buffer element's type. |
capint | Buffer capacity's type to use. Use size_t for large buffers. |
avir::CBuffer< T, capint >::CBuffer | ( | const capint | aCapacity, |
const int | aAlignment = 0 |
||
) |
Constructor creates the buffer with the specified capacity.
aCapacity | Buffer's capacity. |
aAlignment | Buffer's required memory address alignment. 0 - use stdlib's default alignment. |
void avir::CBuffer< T, capint >::alloc | ( | const capint | aCapacity, |
const int | aAlignment = 0 |
||
) |
Function allocates memory so that the specified number of elements can be stored in *this buffer object.
aCapacity | Storage for this number of elements to allocate. |
aAlignment | Buffer's required memory address alignment, power-of-2 values only. 0 - use stdlib's default alignment. |
void avir::CBuffer< T, capint >::forceCapacity | ( | const capint | NewCapacity | ) |
Function "forces" *this buffer to have an arbitary capacity. Calling this function invalidates all further operations except deleting *this object. This function should not be usually used at all. Function can be used to "model" certain buffer capacity without calling a costly memory allocation function.
NewCapacity | A new "forced" capacity. |
void avir::CBuffer< T, capint >::free | ( | ) |
Function deallocates any previously allocated buffer.
capint avir::CBuffer< T, capint >::getCapacity | ( | ) | const |
void avir::CBuffer< T, capint >::increaseCapacity | ( | const capint | NewCapacity, |
const bool | DoDataCopy = true |
||
) |
Function reallocates *this buffer to a larger size so that it will be able to hold the specified number of elements. Downsizing is not performed. Alignment is not changed.
NewCapacity | New (increased) capacity. |
DoDataCopy | "True" if data in the buffer should be retained. |
void avir::CBuffer< T, capint >::truncateCapacity | ( | const capint | NewCapacity | ) |
Function "truncates" (reduces) capacity of the buffer without reallocating it. Alignment is not changed.
NewCapacity | New required capacity. |
void avir::CBuffer< T, capint >::updateCapacity | ( | const capint | ReqCapacity | ) |
Function increases capacity so that the specified number of elements can be stored. This function increases the previous capacity value by third the current capacity value until space for the required number of elements is available. Alignment is not changed.
ReqCapacity | Required capacity. |