walberla::field::FieldAllocator< T > Class Template Referenceabstract

Detailed Description

template<typename T>
class walberla::field::FieldAllocator< T >

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>

+ Inheritance diagram for walberla::field::FieldAllocator< T >:

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_treferenceCounts_
 

Member Typedef Documentation

◆ BaseType

template<typename T >
using walberla::field::FieldAllocator< T >::BaseType = typename std::conditional<VectorTrait<T>::F_SIZE!=0, typename VectorTrait<T>::OutputType, T>::type

Constructor & Destructor Documentation

◆ ~FieldAllocator()

template<typename T >
virtual walberla::field::FieldAllocator< T >::~FieldAllocator ( )
virtualdefault

Member Function Documentation

◆ allocate() [1/2]

template<typename T >
T* walberla::field::FieldAllocator< T >::allocate ( uint_t  allocSize)
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() )

◆ allocate() [2/2]

template<typename T >
T* walberla::field::FieldAllocator< T >::allocate ( uint_t  size0,
uint_t  size1,
uint_t  size2,
uint_t  size3,
uint_t allocSize1,
uint_t allocSize2,
uint_t allocSize3 
)
inline

Allocate memory for a field of given sizes and initializes reference counter with one.

Parameters
size0,size1,size2,size3The 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,allocSize3Output 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.

◆ allocateMemory() [1/2]

template<typename T >
virtual T* walberla::field::FieldAllocator< T >::allocateMemory ( uint_t  size)
protectedpure virtual

◆ allocateMemory() [2/2]

template<typename T >
virtual T* walberla::field::FieldAllocator< T >::allocateMemory ( uint_t  size0,
uint_t  size1,
uint_t  size2,
uint_t  size3,
uint_t allocSize1,
uint_t allocSize2,
uint_t allocSize3 
)
protectedpure virtual

◆ deallocate()

template<typename T >
virtual void walberla::field::FieldAllocator< T >::deallocate ( T *&  values)
protectedpure virtual

Deallocates memory that has been allocated using allocate()

Parameters
valuesReturn value of allocate function()

Implemented in walberla::field::StdFieldAlloc< T >, walberla::field::AllocateAligned< T, alignment >, and walberla::gpu::HostFieldAllocator< T, HostAllocFlags >.

◆ decrementReferenceCount()

template<typename T >
bool walberla::field::FieldAllocator< T >::decrementReferenceCount ( T *  mem)
inline

Decrements the reference count for the given pointer.

Parameters
mema pointer that was returned by the allocate function

A memory region is freed only when the reference count is zero.

Returns
true if memory was freed, false if some other field still uses the memory

◆ incrementReferenceCount()

template<typename T >
void walberla::field::FieldAllocator< T >::incrementReferenceCount ( T *  mem)
inline

Increments the reference count for the given pointer.

Parameters
mema pointer that was returned by the allocate function

The reference counter is the number of field objects that currently use the allocated memory region

◆ referenceCount()

template<typename T >
uint_t walberla::field::FieldAllocator< T >::referenceCount ( T *  mem) const
inline

◆ setInnerGhostLayerSize()

template<typename T >
virtual void walberla::field::FieldAllocator< T >::setInnerGhostLayerSize ( uint_t  )
inlinevirtual

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