Allocation Strategy base class for fields.
The base class handles reference counting, and has purely virtual member functions that have to be implemented by concrete strategy.
#include <FieldAllocator.h>
Public Types | |
using | BaseType = typename std::conditional< VectorTrait< T >::F_SIZE!=0, typename VectorTrait< T >::OutputType, T >::type |
Public Member Functions | |
virtual | ~FieldAllocator ()=default |
T * | allocate (uint_t size0, uint_t size1, uint_t size2, uint_t size3, uint_t &allocSize1, uint_t &allocSize2, uint_t &allocSize3) |
Allocate memory for a field of given sizes and initializes reference counter with one. More... | |
virtual void | setInnerGhostLayerSize (uint_t) |
T * | allocate (uint_t allocSize) |
Allocate memory of the given size. More... | |
void | incrementReferenceCount (T *mem) |
Increments the reference count for the given pointer. More... | |
bool | decrementReferenceCount (T *mem) |
Decrements the reference count for the given pointer. More... | |
uint_t | referenceCount (T *mem) const |
Protected Member Functions | |
virtual T * | allocateMemory (uint_t size0, uint_t size1, uint_t size2, uint_t size3, uint_t &allocSize1, uint_t &allocSize2, uint_t &allocSize3)=0 |
Same as allocated, without handling of reference counter. More... | |
virtual T * | allocateMemory (uint_t size)=0 |
Same as allocated, without handling of reference counter. More... | |
virtual void | deallocate (T *&values)=0 |
Deallocates memory that has been allocated using allocate() More... | |
Additional Inherited Members | |
Static Private Attributes inherited from walberla::field::FieldAllocatorBase< std::conditional< VectorTrait< T >::F_SIZE!=0, VectorTrait< T >::OutputType, T >::type > | |
static std::map< std::conditional< VectorTrait< T >::F_SIZE!=0, VectorTrait< T >::OutputType, T >::type *, uint_t > | referenceCounts_ |
using walberla::field::FieldAllocator< T >::BaseType = typename std::conditional<VectorTrait<T>::F_SIZE!=0, typename VectorTrait<T>::OutputType, T>::type |
|
virtualdefault |
|
inline |
Allocate memory of the given size.
This is used by the field when a memory portion of the same size as an already allocated region (for example in clone() )
|
inline |
Allocate memory for a field of given sizes and initializes reference counter with one.
size0,size1,size2,size3 | The size of the field. size0*size1*size2*size3 is the minimum amount of memory that has to be allocated. size0 is the size of the outermost (slowest) coordinate, size3 the size of the fastest. |
allocSize1,allocSize2,allocSize3 | Output parameters. The actual size of the allocation may be bigger. Here allocSize* can be bigger than size* if alignment >0. There is no allocSize0, since extra allocations (padding) for the outer coordinate do not make sense. |
|
protectedpure virtual |
Same as allocated, without handling of reference counter.
Implemented in walberla::field::StdFieldAlloc< T >, walberla::field::AllocateAligned< T, alignment >, and walberla::gpu::HostFieldAllocator< T, HostAllocFlags >.
|
protectedpure virtual |
Same as allocated, without handling of reference counter.
Implemented in walberla::field::StdFieldAlloc< T >, walberla::field::AllocateAligned< T, alignment >, and walberla::gpu::HostFieldAllocator< T, HostAllocFlags >.
|
protectedpure virtual |
Deallocates memory that has been allocated using allocate()
values | Return value of allocate function() |
Implemented in walberla::field::StdFieldAlloc< T >, walberla::field::AllocateAligned< T, alignment >, and walberla::gpu::HostFieldAllocator< T, HostAllocFlags >.
|
inline |
Decrements the reference count for the given pointer.
mem | a pointer that was returned by the allocate function |
A memory region is freed only when the reference count is zero.
|
inline |
Increments the reference count for the given pointer.
mem | a pointer that was returned by the allocate function |
The reference counter is the number of field objects that currently use the allocated memory region
|
inline |
|
inlinevirtual |
Reimplemented in walberla::field::AllocateAligned< T, alignment >.