34 #ifndef SOMAIO_ALLOCATOR_ALLOCATOR_H 35 #define SOMAIO_ALLOCATOR_ALLOCATOR_H 67 virtual char *
allocate(
size_t n,
size_t elemsize,
69 virtual void deallocate(
char *ptr,
size_t n,
size_t elemsize )
const = 0;
87 virtual char *
allocate(
size_t n,
size_t elemsize,
89 virtual void deallocate(
char *ptr,
size_t n,
size_t sz )
const;
113 virtual char *
allocate(
size_t n,
size_t elemsize,
115 virtual void deallocate(
char *ptr,
size_t n,
size_t sz )
const;
185 MAP_RO = ReadOnlyMap,
188 MAP_RW = ReadWriteMap,
209 float usefactor = 1 );
212 static bool isMMapCompatible(
bool ascii,
int byteorder,
213 bool scalefactored =
false,
224 static void memSizes(
offset_t & ram,
269 bool isDiskformatOK =
false,
270 float usefactor = 1 );
274 float usefactor = 1 );
277 const std::string & filename,
279 bool isDiskformatOK =
false,
280 float usefactor = 1 );
291 template<
typename T> T*
allocate( T*& ptr,
size_t n )
const;
292 template<
typename T>
void deallocate( T* ptr,
size_t n )
const;
294 MappingMode allocatorType()
const;
297 void setAccessMode( DataAccess mode );
309 float useFactor()
const;
310 void setUseFactor(
float x );
311 bool allowsMemoryMapping()
const;
312 void setAllowsMemoryMapping(
bool x );
321 mutable bool _allocated;
322 mutable bool _forced;
336 if( !_alloc || !_forced ) {
347 ptr =
reinterpret_cast<T*
>( _alloc->allocate( n,
sizeof( T ), _datasource.get() ) );
349 #warning uninitialized_fill_n not present in Microsoft standard includes 353 std::uninitialized_fill_n( ptr, n, T() );
367 #if __cplusplus >= 201100 370 for(
size_t i=0; i<n; ++i )
373 std::_Destroy( ptr, ptr + n );
376 _alloc->deallocate( reinterpret_cast<char*>( ptr ), n,
sizeof( T ) );
DataAccess accessMode() const
static const carto::rc_ptr< DataSource > none()
An empty ref-counter that is more convenient than calling a constructor of rc_ptr<DataSource> (useful...
const carto::rc_ptr< DataSource > dataSource() const
This value is used for sub-volumes or fake volumes using data that are already allocated by another s...
static const LowLevelAllocator & lowLevelAllocator(MappingMode m)
virtual bool canDuplicate() const
AllocatorStrategy::DataAccess DataAccess
virtual ~LowLevelAllocator()
Normal allocation mode: allocation in main memory.
const carto::rc_ptr< DataSourceInfo > dataSourceInfo() const
void setAllowsMemoryMapping(bool x)
Abstraction layer for various data sources (file, buffer, socket...).
Mode for read-only access.
DataAccess
Data access modes, they describe what you intend to do with data to be read.
carto::rc_ptr< DataSourceInfo > dataSourceInfo()
bool allowsMemoryMapping() const
virtual char * allocate(size_t n, size_t elemsize, DataSource *datasource) const =0
AllocatorStrategy::MappingMode MappingMode
static const MemoryAllocator & singleton()
Abstract base class for actual allocators types.
static MappingMode mappingMode(DataAccess mode, offset_t buflen, const DataSource *datasource, bool isDiskformatOK, float usefactor=1)
Determines optimal allocator for a data file.
std::ostream & operator<<(std::ostream &os, const MemoryAllocator &thing)
unsigned long long offset_t
Offsets are 64 bits if supported.
carto::rc_ptr< DataSource > dataSource()
virtual void deallocate(char *ptr, size_t n, size_t elemsize) const =0
This allocator doesn't allocate anything.
T * allocate(T *&ptr, size_t n) const
return value is the same as modifiable input param ptr
Mode for internal modification.
void deallocate(T *ptr, size_t n) const
Determination of the allocation type depending of the buffer size to allocate and the disk format of ...
Mode for read/write access, the input file will be modified and needs read/write permissions.