PCL
pcl::Allocator< T, A > Class Template Reference

Provides memory allocation for PCL containers. More...

#include <Allocator.h>

Inherits A.

Public Member Functions

 Allocator ()=default
 
 Allocator (const A &a)
 
 Allocator (const Allocator< T, A > &)=default
 
T * Allocate (size_type n, size_type extra=0)
 
void Deallocate (T *p)
 
size_type MaxLength () const
 
size_type PagedLength (size_type n) const
 
size_type ReallocatedLength (size_type currentLength, size_type newLength) const
 

Detailed Description

template<class T, class A>
class pcl::Allocator< T, A >

Allocator inherits directly from its template argument A, which corresponds to a block allocator class. A block allocator is responsible for allocation and deallocation of untyped blocks of contiguous memory. Allocator inherits block allocation capabilities and specializes them for allocation of a particular type T.

The type T must have default and copy construction semantics.

Besides the default and copy constructors, the block allocator class A must define the following member functions:

size_type A::MaxSize() const
size_t size_type
Definition: Defs.h:609

Returns the maximum size in bytes that the block allocator is able to allocate as a contiguous memory block.

size_type A::BlockSize( size_type n ) const

Returns the size in bytes of an allocation block suitable to store at least n contiguous bytes. Allocator uses this block size to reserve memory in chunks of optimized length. This greatly improves efficiency of containers because it minimizes the frequency of allocation/deallocation operations.

size_type A::ReallocatedBlockSize( size_type currentSize, size_type newSize ) const

Returns the size in bytes of a reallocated block. currentSize is the current size in bytes of the block being reallocated, and newSize is the requested block size. This function is similar to A::BlockSize(), but it is called for reallocation of already existing data blocks, for example before deleting a subset of container elements.

void* AllocateBlock( size_type sz )

Custom allocation routine. Allocates a contiguous memory block of length sz in bytes, and returns the address of the first byte in the newly allocated block.

void DeallocateBlock( void* p )

Custom deallocation routine. Deallocates a contiguous block of memory that has been previously allocated by any allocator of class A.

StandardAllocator is an example of a block allocator that uses the standard new and delete operators.

See also
StandardAllocator

Definition at line 131 of file Allocator.h.

Constructor & Destructor Documentation

◆ Allocator() [1/3]

template<class T , class A >
pcl::Allocator< T, A >::Allocator ( )
default

Default constructor.

Referenced by pcl::IndirectArray< T, A >::Allocator().

◆ Allocator() [2/3]

template<class T , class A >
pcl::Allocator< T, A >::Allocator ( const Allocator< T, A > &  )
default

Copy constructor.

◆ Allocator() [3/3]

template<class T , class A >
pcl::Allocator< T, A >::Allocator ( const A &  a)
inline

Constructs an Allocator instance as a copy of other block allocator.

Definition at line 148 of file Allocator.h.

Member Function Documentation

◆ Allocate()

template<class T , class A >
T* pcl::Allocator< T, A >::Allocate ( size_type  n,
size_type  extra = 0 
)
inline

Allocates a contiguous block of memory, sufficient to store at least n instance of class T. Optionally, allocates the necessary space for n objects plus extra additional bytes.

Returns the starting address of the allocated block.

Note
This member function does not construct any T instance; it only allocates the required memory to store n instances of T.

Definition at line 163 of file Allocator.h.

◆ Deallocate()

template<class T , class A >
void pcl::Allocator< T, A >::Deallocate ( T *  p)
inline

Deallocates a block of memory.

Note
This member function does not destruct any T instance; it only deallocates a previously allocated block where an unspecified number of T instances might be stored (either constructed or not).

Definition at line 177 of file Allocator.h.

◆ MaxLength()

template<class T , class A >
size_type pcl::Allocator< T, A >::MaxLength ( ) const
inline

Returns the maximum number of instances of class T that this allocator can allocate.

Definition at line 188 of file Allocator.h.

◆ PagedLength()

template<class T , class A >
size_type pcl::Allocator< T, A >::PagedLength ( size_type  n) const
inline

Returns the length of a newly allocated data block.

Given a number n of T instances, returns the corresponding paged length for this allocator. The paged length is the actual number of T instances that would be allocated instead of n, which depends on the block allocation policy implemented by the block allocator class.

The value returned by this member function is always greater than or equal to n.

See also
ShrunkLength()

Definition at line 206 of file Allocator.h.

◆ ReallocatedLength()

template<class T , class A >
size_type pcl::Allocator< T, A >::ReallocatedLength ( size_type  currentLength,
size_type  newLength 
) const
inline

Returns the length of a reallocated data block.

Parameters
currentLengthThe current length of an allocated data block.
newLengthThe new length of the reallocated data block.

The returned length is the actual number of T instances that would be allocated instead of newLength, which depends on the block allocation policy implemented by the block allocator class.

The value returned by this member function is always greater than or equal to n.

See also
PagedLength()

Definition at line 227 of file Allocator.h.


The documentation for this class was generated from the following file: