AVIR
High-quality pro image resizing library
 
Loading...
Searching...
No Matches
avir::CBuffer< T, capint > Class Template Reference

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.
 
CBufferoperator= (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.
 

Detailed Description

template<typename 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. 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.

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

Constructor & Destructor Documentation

◆ CBuffer() [1/2]

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

Creates the buffer with the specified capacity.

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

◆ CBuffer() [2/2]

template<typename T, typename capint = int>
avir::CBuffer< T, capint >::CBuffer ( const CBuffer< T, capint > & Source)

Completely copies the specified buffer.

Parameters
SourceSource buffer.

Member Function Documentation

◆ alloc()

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

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.

◆ forceCapacity()

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

Parameters
NewCapacityA new "forced" capacity.

◆ increaseCapacity()

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

Parameters
NewCapacityNew (increased) capacity.
DoDataCopytrue, if data in the buffer should be retained.

◆ operator=()

template<typename T, typename capint = int>
CBuffer & avir::CBuffer< T, capint >::operator= ( const CBuffer< T, capint > & Source)

Completely copies the specified buffer.

Parameters
SourceSource buffer.
Returns
Reference to this object after the copy operation.

◆ truncateCapacity()

template<typename T, typename capint = int>
void avir::CBuffer< T, capint >::truncateCapacity ( const capint NewCapacity)

"Truncates" (reduces) capacity of this buffer, without reallocating it.

Alignment is not changed.

Parameters
NewCapacityNew required capacity.

◆ updateCapacity()

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

Parameters
ReqCapacityRequired capacity.