soma-io 6.0.6
soma::AllocatorContext Class Reference

Allocation context. More...

#include <soma-io/allocator/allocator.h>

Public Types

typedef AllocatorStrategy::DataAccess DataAccess
 
typedef AllocatorStrategy::MappingMode MappingMode
 

Public Member Functions

 AllocatorContext (DataAccess mode=AllocatorStrategy::InternalModif, carto::rc_ptr< DataSource > datasource=DataSource::none(), bool isDiskformatOK=false, float usefactor=1)
 Constructor from a DataSource.
 
 AllocatorContext (DataAccess mode, carto::rc_ptr< DataSourceInfo > datasourceinfo, float usefactor=1)
 Constructor from a DataSourceInfo.
 
 AllocatorContext (DataAccess mode, const std::string &filename, offset_t offset=0, bool isDiskformatOK=false, float usefactor=1)
 Constructor from a filename.
 
 AllocatorContext (DataAccess mode, float usefactor)
 Constructor without pre-existing DataSource.
 
 AllocatorContext (const LowLevelAllocator *alloc)
 Constructor from a LLA.
 
 AllocatorContext (const AllocatorContext &)
 Constructor by copy.
 
 ~AllocatorContext ()
 
AllocatorContextoperator= (const AllocatorContext &)
 
template<typename T>
T * allocate (T *&ptr, size_t n) const
 return value is the same as modifiable input param ptr
 
template<typename T>
void deallocate (T *ptr, size_t n) const
 
bool canDuplicate () const
 
MappingMode allocatorType () const
 
DataAccess accessMode () const
 
void setAccessMode (DataAccess mode)
 
void setDataSource (carto::rc_ptr< DataSource > datasource)
 AllocatorContext becomes owner of datasource.
 
const carto::rc_ptr< DataSourcedataSource () const
 
carto::rc_ptr< DataSourcedataSource ()
 
void setDataSourceInfo (carto::rc_ptr< DataSourceInfo > dsi)
 AllocatorContext becomes owner od datasourceinfo.
 
const carto::rc_ptr< DataSourceInfodataSourceInfo () const
 
carto::rc_ptr< DataSourceInfodataSourceInfo ()
 
bool isAllocated () const
 
float useFactor () const
 
void setUseFactor (float x)
 
bool allowsMemoryMapping () const
 
void setAllowsMemoryMapping (bool x)
 

Static Public Member Functions

static const AllocatorContextfast ()
 

Detailed Description

Allocation context.

The allocators system is globally described on a separate Allocators system page.

More specifically, AllocatorContext is the entry point to this
allocation system: only this class has generally to be used by programmers. It handles a switch to the appropriate low-level allocator (LowLevelAllocator) according to the amount of memory available, the size of the data block to be allocated, and to what is intended to be done with it.

The switch mechanism is itself in large part deported to another class: AllocatorStrategy which also provides some constant enums used by AllocatorContext. This is perhaps a bad idea and both classes might be merged in the future.

In order to accelerate allocation, or to be sure that allocation is done in the intended mode (which may be important in some cases), this switching mechanism can be bypassed by directly providing a LowLevelAllocator. Such low-level allocators are singletons and should never be created by hand: use their singleton() static methods.

Definition at line 260 of file allocator.h.

Member Typedef Documentation

◆ DataAccess

typedef AllocatorStrategy::DataAccess soma::AllocatorContext::DataAccess

Definition at line 263 of file allocator.h.

◆ MappingMode

typedef AllocatorStrategy::MappingMode soma::AllocatorContext::MappingMode

Definition at line 264 of file allocator.h.

Constructor & Destructor Documentation

◆ AllocatorContext() [1/6]

soma::AllocatorContext::AllocatorContext ( DataAccess mode = AllocatorStrategy::InternalModif,
carto::rc_ptr< DataSource > datasource = DataSource::none(),
bool isDiskformatOK = false,
float usefactor = 1 )

◆ AllocatorContext() [2/6]

soma::AllocatorContext::AllocatorContext ( DataAccess mode,
carto::rc_ptr< DataSourceInfo > datasourceinfo,
float usefactor = 1 )

Constructor from a DataSourceInfo.

◆ AllocatorContext() [3/6]

soma::AllocatorContext::AllocatorContext ( DataAccess mode,
const std::string & filename,
offset_t offset = 0,
bool isDiskformatOK = false,
float usefactor = 1 )

Constructor from a filename.

◆ AllocatorContext() [4/6]

soma::AllocatorContext::AllocatorContext ( DataAccess mode,
float usefactor )

Constructor without pre-existing DataSource.

◆ AllocatorContext() [5/6]

soma::AllocatorContext::AllocatorContext ( const LowLevelAllocator * alloc)

Constructor from a LLA.

◆ AllocatorContext() [6/6]

soma::AllocatorContext::AllocatorContext ( const AllocatorContext & )

Constructor by copy.

References AllocatorContext().

◆ ~AllocatorContext()

soma::AllocatorContext::~AllocatorContext ( )

Member Function Documentation

◆ accessMode()

DataAccess soma::AllocatorContext::accessMode ( ) const
inline

Definition at line 296 of file allocator.h.

Referenced by soma::FormatReader< T >::setupAndRead().

◆ allocate()

template<typename T>
T * soma::AllocatorContext::allocate ( T *& ptr,
size_t n ) const
inline

return value is the same as modifiable input param ptr

Definition at line 333 of file allocator.h.

References allocate(), soma::AllocatorStrategy::lowLevelAllocator(), soma::AllocatorStrategy::mappingMode(), and soma::MemoryAllocator::singleton().

Referenced by soma::AllocatedVector< T >::allocate(), allocate(), and operator=().

◆ allocatorType()

MappingMode soma::AllocatorContext::allocatorType ( ) const

◆ allowsMemoryMapping()

bool soma::AllocatorContext::allowsMemoryMapping ( ) const
inline

Definition at line 383 of file allocator.h.

References allowsMemoryMapping().

Referenced by allowsMemoryMapping(), and setUseFactor().

◆ canDuplicate()

bool soma::AllocatorContext::canDuplicate ( ) const

◆ dataSource() [1/2]

carto::rc_ptr< DataSource > soma::AllocatorContext::dataSource ( )
inline

Definition at line 302 of file allocator.h.

◆ dataSource() [2/2]

const carto::rc_ptr< DataSource > soma::AllocatorContext::dataSource ( ) const
inline

Definition at line 301 of file allocator.h.

◆ dataSourceInfo() [1/2]

carto::rc_ptr< DataSourceInfo > soma::AllocatorContext::dataSourceInfo ( )
inline

Definition at line 306 of file allocator.h.

◆ dataSourceInfo() [2/2]

const carto::rc_ptr< DataSourceInfo > soma::AllocatorContext::dataSourceInfo ( ) const
inline

Definition at line 305 of file allocator.h.

◆ deallocate()

template<typename T>
void soma::AllocatorContext::deallocate ( T * ptr,
size_t n ) const
inline

Definition at line 363 of file allocator.h.

References deallocate(), and soma::MemoryAllocator::singleton().

Referenced by deallocate(), and operator=().

◆ fast()

static const AllocatorContext & soma::AllocatorContext::fast ( )
static

References AllocatorContext().

◆ isAllocated()

bool soma::AllocatorContext::isAllocated ( ) const
inline

◆ operator=()

AllocatorContext & soma::AllocatorContext::operator= ( const AllocatorContext & )

◆ setAccessMode()

void soma::AllocatorContext::setAccessMode ( DataAccess mode)

◆ setAllowsMemoryMapping()

void soma::AllocatorContext::setAllowsMemoryMapping ( bool x)
inline

Definition at line 389 of file allocator.h.

References setAllowsMemoryMapping().

Referenced by setAllowsMemoryMapping(), and setUseFactor().

◆ setDataSource()

void soma::AllocatorContext::setDataSource ( carto::rc_ptr< DataSource > datasource)

AllocatorContext becomes owner of datasource.

◆ setDataSourceInfo()

void soma::AllocatorContext::setDataSourceInfo ( carto::rc_ptr< DataSourceInfo > dsi)

AllocatorContext becomes owner od datasourceinfo.

◆ setUseFactor()

void soma::AllocatorContext::setUseFactor ( float x)

◆ useFactor()

float soma::AllocatorContext::useFactor ( ) const

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