soma-io  5.0.5
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. More...
 
 AllocatorContext (DataAccess mode, carto::rc_ptr< DataSourceInfo > datasourceinfo, float usefactor=1)
 Constructor from a DataSourceInfo. More...
 
 AllocatorContext (DataAccess mode, const std::string &filename, offset_t offset=0, bool isDiskformatOK=false, float usefactor=1)
 Constructor from a filename. More...
 
 AllocatorContext (DataAccess mode, float usefactor)
 Constructor without pre-existing DataSource. More...
 
 AllocatorContext (const LowLevelAllocator *alloc)
 Constructor from a LLA. More...
 
 AllocatorContext (const AllocatorContext &)
 Constructor by copy. More...
 
 ~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 More...
 
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. More...
 
const carto::rc_ptr< DataSourcedataSource () const
 
carto::rc_ptr< DataSourcedataSource ()
 
void setDataSourceInfo (carto::rc_ptr< DataSourceInfo > dsi)
 AllocatorContext becomes owner od datasourceinfo. More...
 
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)
 

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

◆ MappingMode

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 
)

Constructor from a DataSource.

◆ 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.

◆ ~AllocatorContext()

soma::AllocatorContext::~AllocatorContext ( )

Member Function Documentation

◆ accessMode()

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

◆ 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 330 of file allocator.h.

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

Referenced by soma::AllocatedVector< T >::allocate().

◆ allocatorType()

MappingMode soma::AllocatorContext::allocatorType ( ) const

◆ allowsMemoryMapping()

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

Definition at line 380 of file allocator.h.

◆ canDuplicate()

bool soma::AllocatorContext::canDuplicate ( ) const

◆ dataSource() [1/2]

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

Definition at line 301 of file allocator.h.

Referenced by soma::FormatReader< carto::GenericObject >::read().

◆ dataSource() [2/2]

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

Definition at line 302 of file allocator.h.

◆ dataSourceInfo() [1/2]

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

Definition at line 305 of file allocator.h.

◆ dataSourceInfo() [2/2]

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

Definition at line 306 of file allocator.h.

◆ deallocate()

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

Definition at line 360 of file allocator.h.

References soma::MemoryAllocator::singleton().

Referenced by soma::AllocatedVector< T >::free().

◆ 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 386 of file allocator.h.

◆ 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.

Referenced by soma::Reader< T >::read().

◆ setUseFactor()

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

◆ useFactor()


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