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 Member Functions

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...
 

Static Private Attributes

static std::map< T *, uint_treferenceCounts_ = std::map<T*,uint_t>()
 

Member Function Documentation

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
size*The size of the field. size0*size1*size2*size*3 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.
allocSize*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.
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() )

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
template<typename T >
virtual T* walberla::field::FieldAllocator< T >::allocateMemory ( uint_t  size)
protectedpure virtual
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::cuda::HostFieldAllocator< T, cudaHostAllocFlags >.

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

Decrements the reference count for the given pointer.

Parameters
allocatedPointera 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
template<typename T >
void walberla::field::FieldAllocator< T >::incrementReferenceCount ( T *  mem)
inline

Increments the reference count for the given pointer.

Parameters
allocatedPointera pointer that was returned by the allocate function

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

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

Member Data Documentation

template<typename T >
std::map< T *, uint_t > walberla::field::FieldAllocator< T >::referenceCounts_ = std::map<T*,uint_t>()
staticprivate

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