libtgd 5.0
A library that makes working with multidimensional arrays in C++ easy
TGD::MmapAllocator Class Referencefinal

An mmap-based allocator that allows to work with arrays that do not fit into main memory. More...

#include <alloc.hpp>

Inherits TGD::Allocator.

Public Types

enum  Type { Private , NewFile , ExistingFileReadOnly , ExistingFileReadWrite }
 

Public Member Functions

 MmapAllocator (const std::string &dirName=".")
 Constructor for a private mmap allocator.
 
 MmapAllocator (const std::string &fileName, Type type)
 Constructor for a named-file mmap allocator.
 
virtual ~MmapAllocator ()
 Destructor.
 
virtual unsigned char * allocate (std::size_t n) const override
 Allocates n bytes.
 
virtual std::function< void(unsigned char *p)> getDeallocator (std::size_t n) const override
 Returns a function that deallocates n bytes at the given pointer.
 
virtual bool clearsMemory () const override
 Returns whether this allocator clears allocated memory.
 
- Public Member Functions inherited from TGD::Allocator
 Allocator ()
 Constructor.
 
virtual ~Allocator ()
 Destructor.
 

Detailed Description

An mmap-based allocator that allows to work with arrays that do not fit into main memory.

Member Enumeration Documentation

◆ Type

Enumerator
Private 

Allocation in a specific directory, without a visible file name.

NewFile 

Shared allocation in a newly created file with a given name.

ExistingFileReadOnly 

Shared allocation in an existing file, read only.

ExistingFileReadWrite 

Shared allocation in an existing file, read and write.

Constructor & Destructor Documentation

◆ MmapAllocator() [1/2]

TGD::MmapAllocator::MmapAllocator ( const std::string & dirName = ".")
inline

Constructor for a private mmap allocator.

Parameters
dirNameDirectory in which the private file is created.

Creates a private temporary file in the given directory. Typical values for dirName are "." for the current directory, or a directory taken from the TMPDIR environment variable, if available.

◆ MmapAllocator() [2/2]

TGD::MmapAllocator::MmapAllocator ( const std::string & fileName,
Type type )
inline

Constructor for a named-file mmap allocator.

Parameters
fileNameName of the file.
typeType of file usage.

The type can be NewFile, which will create a new file (or possibly overwrites an existing file with the same name), or ExistingFileReadOnly, which will open the specified file in read-only mode, or ExistingFileReadWrite, which will open the specified file in read-write mode.

◆ ~MmapAllocator()

virtual TGD::MmapAllocator::~MmapAllocator ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ allocate()

virtual unsigned char * TGD::MmapAllocator::allocate ( std::size_t n) const
inlineoverridevirtual

Allocates n bytes.

Reimplemented from TGD::Allocator.

◆ clearsMemory()

virtual bool TGD::MmapAllocator::clearsMemory ( ) const
inlineoverridevirtual

Returns whether this allocator clears allocated memory.

Reimplemented from TGD::Allocator.

◆ getDeallocator()

virtual std::function< void(unsigned char *p)> TGD::MmapAllocator::getDeallocator ( std::size_t n) const
inlineoverridevirtual

Returns a function that deallocates n bytes at the given pointer.

Reimplemented from TGD::Allocator.


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