PCL
pcl::StandardAllocator Class Reference

A block allocator class that uses the standard new and delete operators. More...

#include <StdAlloc.h>

Public Member Functions

 StandardAllocator (bool fastGrowth=true, bool canShrink=true)
 
 StandardAllocator (const StandardAllocator &)=default
 
void * AllocateBlock (size_type sz)
 
size_type BlockSize (size_type n) const
 
void DeallocateBlock (void *p)
 
void DisableFastGrowth (bool disable=true)
 
void DisableShrinking (bool disable=true)
 
void EnableFastGrowth (bool enable=true)
 
void EnableShrinking (bool enable=true)
 
bool IsFastGrowthEnabled () const
 
bool IsShrinkingEnabled () const
 
size_type MaxSize () const
 
size_type ReallocatedBlockSize (size_type currentSize, size_type newSize) const
 

Detailed Description

StandardAllocator is a block allocator class. It is used by default for all container classes in PCL. It defines default block sizing and growing strategies that work efficiently in most cases.

For a complete description of block allocators and their fundamental role in PCL, read the documentation for the Allocator class.

See also
Allocator

Definition at line 81 of file StdAlloc.h.

Constructor & Destructor Documentation

◆ StandardAllocator() [1/2]

pcl::StandardAllocator::StandardAllocator ( bool  fastGrowth = true,
bool  canShrink = true 
)
inline

Constructs a StandardAllocator object.

Parameters
fastGrowthWhether to enable the fast block size growing policy for this allocator.
canShrinkWhether to enable the block shrinking policy for this allocator.

See the IsFastGrowthEnabled() and IsShrinkingEnabled() member functions for more information on allocation policies.

Definition at line 97 of file StdAlloc.h.

◆ StandardAllocator() [2/2]

pcl::StandardAllocator::StandardAllocator ( const StandardAllocator )
default

Copy constructor.

Member Function Documentation

◆ AllocateBlock()

void* pcl::StandardAllocator::AllocateBlock ( size_type  sz)
inline

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.

As implemented by StandardAllocator, this member function simply calls ::operator new( sz ).

Note
This member function is mandatory for a block allocator to be usable by the Allocator class.
See also
DeallocateBlock()

Definition at line 197 of file StdAlloc.h.

◆ BlockSize()

size_type pcl::StandardAllocator::BlockSize ( size_type  n) const
inline

Returns the size in bytes of an allocation block suitable for storage of at least n bytes.

See IsFastGrowthEnabled() for more information about block size growing policies in StandardAllocator.

Note
This member function is mandatory for a block allocator to be usable by the Allocator class.
See also
ReallocatedBlockSize(), IsFastGrowthEnabled()

Definition at line 134 of file StdAlloc.h.

◆ DeallocateBlock()

void pcl::StandardAllocator::DeallocateBlock ( void *  p)
inline

Custom deallocation routine. Deallocates a previously allocated contiguous memory block that begins at the specified location p.

As implemented by StandardAllocator, this member function simply calls ::operator delete( p ).

Note
This member function is mandatory for a block allocator to be usable by the Allocator class.
See also
AllocateBlock()

Definition at line 215 of file StdAlloc.h.

◆ DisableFastGrowth()

void pcl::StandardAllocator::DisableFastGrowth ( bool  disable = true)
inline

Disables the fast block size growing policy for StandardAllocator.

See IsFastGrowthEnabled() for more information about block size growing policies.

See also
IsFastGrowthEnabled(), EnableFastGrowth()

Definition at line 268 of file StdAlloc.h.

◆ DisableShrinking()

void pcl::StandardAllocator::DisableShrinking ( bool  disable = true)
inline

Disables a block shrinking policy for StandardAllocator.

See IsShrinkingEnabled() for more information about block shrinking policies.

See also
IsShrinkingEnabled(), EnableShrinking()

Definition at line 312 of file StdAlloc.h.

◆ EnableFastGrowth()

void pcl::StandardAllocator::EnableFastGrowth ( bool  enable = true)
inline

Enables the fast block size growing policy for StandardAllocator.

See IsFastGrowthEnabled() for more information about block size growing policies.

See also
IsFastGrowthEnabled(), DisableFastGrowth()

Definition at line 255 of file StdAlloc.h.

◆ EnableShrinking()

void pcl::StandardAllocator::EnableShrinking ( bool  enable = true)
inline

Enables a block shrinking policy for StandardAllocator.

See IsShrinkingEnabled() for more information about block shrinking policies.

See also
IsShrinkingEnabled(), DisableShrinking()

Definition at line 299 of file StdAlloc.h.

◆ IsFastGrowthEnabled()

bool pcl::StandardAllocator::IsFastGrowthEnabled ( ) const
inline

Returns true iff fast growth is currently enabled for this allocator.

When fast growth is enabled, StandardAllocator provides block sizes that grow exponentially above 64 bytes: 128, 256, 512, 1K, ... 512K, 1M, and so on. This maximizes speed of dynamic allocation operations, but at the cost of more memory wasted by partially used blocks in contiguous-storage containers such as Array or String.

With fast growth disabled, StandardAllocator follows a more conservative scheme to provide reasonable block sizes while preventing excessive memory consumption. For block sizes below 64 kilobytes, blocks grow exponentially to improve efficiency of allocation for small objects, such as short strings. For blocks larger than 64K, block sizes grow by constant chunks of 4K.

The fast block size growing policy is always enabled by default.

See also
EnableFastGrowth(), DisableFastGrowth(), BlockSize()

Definition at line 242 of file StdAlloc.h.

◆ IsShrinkingEnabled()

bool pcl::StandardAllocator::IsShrinkingEnabled ( ) const
inline

Returns true iff block shrinking is currently enabled for this allocator.

When block shrinking is enabled, StandardAllocator allows size reductions for reallocated blocks in calls to the ReallocatedBlockSize(). When block shrinking is disabled, already allocated blocks can only be reallocated with increased lengths.

The block shrinking policy is always enabled by default.

See also
EnableShrinking(), DisableShrinking(), ReallocatedBlockSize()

Definition at line 286 of file StdAlloc.h.

◆ MaxSize()

size_type pcl::StandardAllocator::MaxSize ( ) const
inline

Returns the size in bytes of the largest contiguous block that this object is able to allocate.

StandardAllocator can (theoretically) allocate ~size_type( 0 ) bytes.

Note
This member function is mandatory for a block allocator to be usable by the Allocator class.

Definition at line 117 of file StdAlloc.h.

◆ ReallocatedBlockSize()

size_type pcl::StandardAllocator::ReallocatedBlockSize ( size_type  currentSize,
size_type  newSize 
) const
inline

Returns the size in bytes of a reallocated data block.

Parameters
currentSizeThe current size in bytes of an allocated data block.
newSizeThe new size in bytes of the reallocated data block.

See IsFastGrowthEnabled() and IsShrinkingEnabled() for information about block size allocation and reallocation policies in StandardAllocator.

Note
This member function is mandatory for a block allocator to be usable by the Allocator class.
See also
BlockSize(), IsShrinkingEnabled(), IsFastGrowthEnabled()

Definition at line 179 of file StdAlloc.h.


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