Memory buffer class for element array storage, with capacity tracking. More...
#include <avir.h>
Public Member Functions | |
CBuffer (const capint aCapacity, const int aAlignment=0) | |
Creates the buffer with the specified capacity. | |
CBuffer (const CBuffer &Source) | |
Completely copies the specified buffer. | |
void | alloc (const capint aCapacity, const int aAlignment=0) |
Allocates memory so that the specified number of elements can be stored in this buffer object. | |
void | forceCapacity (const capint NewCapacity) |
"Forces" this buffer to have an arbitary capacity. | |
void | free () |
Deallocates any previously allocated buffer. | |
capint | getCapacity () const |
Returns the capacity of this element buffer. | |
void | increaseCapacity (const capint NewCapacity, const bool DoDataCopy=true) |
Reallocates this buffer to a larger size. | |
operator T* () const | |
Returns pointer to the first buffer element. | |
CBuffer & | operator= (const CBuffer &Source) |
Completely copies the specified buffer. | |
void | truncateCapacity (const capint NewCapacity) |
"Truncates" (reduces) capacity of this buffer, without reallocating it. | |
void | updateCapacity (const capint ReqCapacity) |
Increases capacity so that the specified number of elements can be stored. | |
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. By default, tracks buffer's capacity in a int
variable, which is 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 object construction (initialization) operations. Buffer's required memory address alignment specification is supported.
Uses operators new[]
and delete[]
, 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 ) |
Creates the buffer with the specified capacity.
aCapacity | Buffer's capacity. |
aAlignment | Buffer's required memory address alignment. 0 - use stdlib's default alignment. |
avir::CBuffer< T, capint >::CBuffer | ( | const CBuffer< T, capint > & | Source | ) |
Completely copies the specified buffer.
Source | Source buffer. |
void avir::CBuffer< T, capint >::alloc | ( | const capint | aCapacity, |
const int | aAlignment = 0 ) |
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 | ) |
"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 >::increaseCapacity | ( | const capint | NewCapacity, |
const bool | DoDataCopy = true ) |
Reallocates this buffer to a larger size.
The buffer 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. |
CBuffer & avir::CBuffer< T, capint >::operator= | ( | const CBuffer< T, capint > & | Source | ) |
Completely copies the specified buffer.
Source | Source buffer. |
void avir::CBuffer< T, capint >::truncateCapacity | ( | const capint | NewCapacity | ) |
"Truncates" (reduces) capacity of this buffer, without reallocating it.
Alignment is not changed.
NewCapacity | New required capacity. |
void avir::CBuffer< T, capint >::updateCapacity | ( | const capint | ReqCapacity | ) |
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. |