AVIR
High-quality pro image resizing library
 All Classes Files Functions Variables Typedefs Macros
Public Member Functions | List of all members
avir::CBuffer< T, capint > Class Template Reference

#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
 
CBufferoperator= (const CBuffer &Source)
 
void truncateCapacity (const capint NewCapacity)
 
void updateCapacity (const capint ReqCapacity)
 

Detailed Description

template<class T, typename capint = int>
class avir::CBuffer< T, capint >

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.

Template Parameters
TBuffer element's type.
capintBuffer capacity's type to use. Use size_t for large buffers.

Constructor & Destructor Documentation

template<class T, typename capint = int>
avir::CBuffer< T, capint >::CBuffer ( const capint  aCapacity,
const int  aAlignment = 0 
)

Constructor creates the buffer with the specified capacity.

Parameters
aCapacityBuffer's capacity.
aAlignmentBuffer's required memory address alignment. 0 - use stdlib's default alignment.

Member Function Documentation

template<class T, typename capint = int>
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.

Parameters
aCapacityStorage for this number of elements to allocate.
aAlignmentBuffer's required memory address alignment, power-of-2 values only. 0 - use stdlib's default alignment.
template<class T, typename capint = int>
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.

Parameters
NewCapacityA new "forced" capacity.
template<class T, typename capint = int>
void avir::CBuffer< T, capint >::free ( )

Function deallocates any previously allocated buffer.

template<class T, typename capint = int>
capint avir::CBuffer< T, capint >::getCapacity ( ) const
Returns
The capacity of the element buffer.
template<class T, typename capint = int>
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.

Parameters
NewCapacityNew (increased) capacity.
DoDataCopy"True" if data in the buffer should be retained.
template<class T, typename capint = int>
void avir::CBuffer< T, capint >::truncateCapacity ( const capint  NewCapacity)

Function "truncates" (reduces) capacity of the buffer without reallocating it. Alignment is not changed.

Parameters
NewCapacityNew required capacity.
template<class T, typename capint = int>
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.

Parameters
ReqCapacityRequired capacity.