HTGS  v2.0
The Hybrid Task Graph Scheduler
htgs::IMemoryAllocator< T > Class Template Referenceabstract

Abstract class that describes how memory is allocated and freed. More...

#include <htgs/api/IMemoryAllocator.hpp>

Inheritance diagram for htgs::IMemoryAllocator< T >:
Inheritance graph
Collaboration diagram for htgs::IMemoryAllocator< T >:
Collaboration graph

Public Member Functions

 IMemoryAllocator (size_t size)
 Creates a memory allocator. More...
 
virtual ~IMemoryAllocator ()
 Destructor.
 
virtual T * memAlloc (size_t size)=0
 Pure virtual function that allocates a piece of memory with a specific size. More...
 
virtual T * memAlloc ()=0
 Pure virtual function that allocates a piece of memory. More...
 
virtual void memFree (T *&memory)=0
 Pure virtual function the frees memory. More...
 
- Public Member Functions inherited from htgs::AnyMemoryAllocator
 AnyMemoryAllocator (size_t size)
 Creates a memory allocator. More...
 
virtual ~AnyMemoryAllocator ()
 Destructor.
 
size_t size () const
 Gets the size. More...
 

Detailed Description

template<class T>
class htgs::IMemoryAllocator< T >

Abstract class that describes how memory is allocated and freed.

This class is used in conjunction with TaskGraphConf::addMemoryManagerEdge and is required in order to define how a MemoryManager allocates memory for its memory pool.

If the memory allocator is to be shared among multiple memory managers, then the allocator must be wrapped into a std::shared_ptr.

Example implementation:

class FFTWMemoryAllocator : public htgs::IMemoryAllocator<fftw_complex>
{
FFTWMemoryAllocator(size_t size) : IMemoryAllocator(size) {}
fftw_complex *memAlloc(size_t size) override {
return fftw_alloc_complex(size);
}
fftw_complex *memAlloc() override {
return fftw_alloc_complex(this->size());
}
void memFree(fftw_complex *&memory) override {
fftw_free(memory);
}
};

Example usage:

int memoryPoolSize = 50;
FFTTask *fftTask = new FFTTask();
MatMulTask *matMul = new MatMulTask();
taskGraph->addEdge(fftTask, matMul);
taskGraph->addMemoryManagerEdge("fft", fftTask, new FFTWMemoryAllocator(imageSize), memoryPoolSize, htgs::MMType::Static);
Template Parameters
Tthe memory type

Constructor & Destructor Documentation

◆ IMemoryAllocator()

template<class T>
htgs::IMemoryAllocator< T >::IMemoryAllocator ( size_t  size)
inline

Creates a memory allocator.

Parameters
sizethe number of elements to allocate

Member Function Documentation

◆ memAlloc() [1/2]

template<class T>
virtual T* htgs::IMemoryAllocator< T >::memAlloc ( size_t  size)
pure virtual

Pure virtual function that allocates a piece of memory with a specific size.

Returns
an allocated piece of memory with type T

◆ memAlloc() [2/2]

template<class T>
virtual T* htgs::IMemoryAllocator< T >::memAlloc ( )
pure virtual

Pure virtual function that allocates a piece of memory.

Returns
an allocated piece of memory with type T

◆ memFree()

template<class T>
virtual void htgs::IMemoryAllocator< T >::memFree ( T *&  memory)
pure virtual

Pure virtual function the frees memory.

Parameters
memorythe memory to be freed

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