soma-io  5.1.2
soma::AllocatorStrategy Class Reference

Determination of the allocation type depending of the buffer size to allocate and the disk format of data. More...

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

Public Types

enum  DataAccess { InternalModif , ReadOnly , ReadWrite , NotOwner }
 Data access modes, they describe what you intend to do with data to be read. More...
 
enum  MappingMode {
  Memory , MEM = Memory , MAP , CopyMap ,
  MAP_COPY = CopyMap , ReadOnlyMap , MAP_RO = ReadOnlyMap , ReadWriteMap ,
  MAP_RW = ReadWriteMap , Unallocated
}
 

Static Public Member Functions

static MappingMode mappingMode (DataAccess mode, offset_t buflen, const DataSource *datasource, bool isDiskformatOK, float usefactor=1)
 Determines optimal allocator for a data file. More...
 
static bool isMMapCompatible (bool ascii, int byteorder, bool scalefactored=false, int border=0)
 helper function, tells if memory mapping is directly possible More...
 
static void memSizes (offset_t &ram, offset_t &freeram, offset_t &swap)
 same as above but uses a Header attributed object More...
 
static AllocatorContext allocator (MappingMode mode, carto::rc_ptr< DataSource > ds)
 
static const LowLevelAllocatorlowLevelAllocator (MappingMode m)
 

Detailed Description

Determination of the allocation type depending of the buffer size to allocate and the disk format of data.

The optimal allocation mode depends on:

  • what you intend to do with the data: read only, read / modify / rewrite to disk, read / modify internally but leave it unchanged on disk
  • if data on disk is stored in the same format as the memory format (binary data, no byteswapping, no alignment mismatch, no scalefactor...)
  • the size of data
  • possibly the size of the system memory (total or currently available), but as it cannot be determined in a portable way, this information is likely not to be accessible on every system, so we use absolute threshold instead

Definition at line 150 of file allocator.h.

Member Enumeration Documentation

◆ DataAccess

Data access modes, they describe what you intend to do with data to be read.

Enumerator
InternalModif 

Mode for internal modification.

If memory mapping is enabled, it will be on a copy of the input file (MAP_COPY) because it needs to be writeable but must not modify the original file. It is the safest mode (but not the more efficient), so if you hesitate, take this one.

ReadOnly 

Mode for read-only access.

ReadWrite 

Mode for read/write access, the input file will be modified and needs read/write permissions.

NotOwner 

This value is used for sub-volumes or fake volumes using data that are already allocated by another structure.

Definition at line 155 of file allocator.h.

◆ MappingMode

Enumerator
Memory 
MEM 
MAP 
CopyMap 
MAP_COPY 
ReadOnlyMap 
MAP_RO 
ReadWriteMap 
MAP_RW 
Unallocated 

Definition at line 173 of file allocator.h.

Member Function Documentation

◆ allocator()

static AllocatorContext soma::AllocatorStrategy::allocator ( MappingMode  mode,
carto::rc_ptr< DataSource ds 
)
static

◆ isMMapCompatible()

static bool soma::AllocatorStrategy::isMMapCompatible ( bool  ascii,
int  byteorder,
bool  scalefactored = false,
int  border = 0 
)
static

helper function, tells if memory mapping is directly possible

◆ lowLevelAllocator()

static const LowLevelAllocator& soma::AllocatorStrategy::lowLevelAllocator ( MappingMode  m)
static

◆ mappingMode()

static MappingMode soma::AllocatorStrategy::mappingMode ( DataAccess  mode,
offset_t  buflen,
const DataSource datasource,
bool  isDiskformatOK,
float  usefactor = 1 
)
static

Determines optimal allocator for a data file.

Parameters
modewhat you intend to do tith the data: read only, read/write or read/internally modify it. read/write mode is dangerous: it will allow modifying the original file.
buflensize in bytes of the data to allocate
datasourcedata source to map (file, buffer, stream, ...)
isDiskformatOKtrue if the disk format is exactly the same as the internal memory format (allowing direct memory mapping)
usefactorrate of usage you intend to do with the data, from 0 if you will only use a few bytes of it, to 1 if you intend to make intensive usage of all data. A small value will allow memory mapping on smaller files, and a higher value will avoid it.

Referenced by soma::AllocatorContext::allocate().

◆ memSizes()

static void soma::AllocatorStrategy::memSizes ( offset_t ram,
offset_t freeram,
offset_t swap 
)
static

same as above but uses a Header attributed object

Try to detect memory amounts and fills referenced params. Params are set to 0 if thezy cannor be determined.

Parameters
ramphysical RAM amount
freeramfree RAM amount
swapfree RAM+swap amount

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