1#ifndef DUNE_ALU3DGRIDMEMORY_HH
2#define DUNE_ALU3DGRIDMEMORY_HH
4#include <dune/alugrid/common/alugrid_assert.hh>
11 template<
class T,
int length >
12 class ALUGridFiniteStack;
15 template <
class Object>
18 enum { maxStackObjects = 256 };
19 typedef ::ALUGrid::ALUGridFiniteStack< Object *, maxStackObjects > StackType;
25 StackType &objStack () {
return objStack_; }
28 typedef Object ObjectType;
44 template <
class FactoryType>
45 ObjectType *
getObject(
const FactoryType &factory,
int level);
48 template <
class FactoryType,
class EntityImp>
49 inline ObjectType *
getEntityObject(
const FactoryType& factory,
int level, EntityImp* )
51 if( objStack().empty() )
53 return new ObjectType( EntityImp(factory,level) );
68 inline ObjectType * stackObject()
71 alugrid_assert ( ! objStack().empty() );
73 return objStack().pop();
83 template <
class Object>
template <
class FactoryType>
84 inline typename ALUMemoryProvider<Object>::ObjectType*
86 getObject(
const FactoryType &factory,
int level )
88 if( objStack().empty() )
90 return (
new Object (factory, level) );
98 template <
class Object>
99 inline typename ALUMemoryProvider<Object>::ObjectType *
102 if( objStack().empty() )
104 return new Object () ;
108 return stackObject();
112 template <
class Object>
115 StackType& objStk = objStack();
116 while ( ! objStk.empty() )
118 ObjectType * obj = objStk.pop();
123 template <
class Object>
127 StackType& stk = objStack();
134 template <
class ObjectImp>
135 class ReferenceCountedObject
139 typedef ObjectImp ObjectType;
144 unsigned int& refCount() {
return object_.refCount_; }
145 const unsigned int& refCount()
const {
return object_.refCount_; }
155 object_.invalidate();
159 void operator ++ () { ++ refCount(); }
162 void operator -- () { alugrid_assert ( refCount() > 0 ); --refCount(); }
165 bool operator ! ()
const {
return refCount() == 0; }
168 bool unique ()
const {
return refCount() == 1 ; }
170 const ObjectType& object()
const {
return object_; }
171 ObjectType& object() {
return object_; }
174 template <
class ObjectImp>
178 typedef ObjectImp ObjectType;
179 typedef ReferenceCountedObject< ObjectType > ReferenceCountedObjectType;
180 typedef ALUMemoryProvider< ReferenceCountedObjectType > MemoryPoolType;
182 static MemoryPoolType& memoryPool()
184 static thread_local MemoryPoolType pool;
196 SharedPointer(
const SharedPointer& other )
209 ptr_ = memoryPool().getEmptyObject();
213 void assign(
const SharedPointer& other )
230 memoryPool().freeObject( ptr_ );
242 ptr().object().invalidate();
253 SharedPointer& operator = (
const SharedPointer& other )
255 if( ptr_ != other.ptr_ )
263 operator bool ()
const {
return bool( ptr_ ); }
265 bool operator == (
const SharedPointer& other )
const {
return ptr_ == other.ptr_; }
267 bool unique ()
const {
return ptr().unique(); }
270 ObjectType& operator* () {
return ptr().object(); }
271 const ObjectType& operator* ()
const {
return ptr().object(); }
274 ReferenceCountedObjectType& ptr() { alugrid_assert( ptr_ );
return *ptr_; }
275 const ReferenceCountedObjectType& ptr()
const { alugrid_assert( ptr_ );
return *ptr_; }
277 ReferenceCountedObjectType* ptr_;
organize the memory management for entitys used by the NeighborIterator
Definition: memory.hh:17
ObjectType * getObject(const FactoryType &factory, int level)
i.e. return pointer to Entity
Definition: memory.hh:86
~ALUMemoryProvider()
call deleteEntity
Definition: memory.hh:113
ALUMemoryProvider(const ALUMemoryProvider &org)
copy constructor
Definition: memory.hh:36
void freeObject(ObjectType *obj)
free, move element to stack, returns NULL
Definition: memory.hh:124
ObjectType * getEmptyObject()
return object, if created default constructor is used
Definition: memory.hh:100
ALUMemoryProvider()
default constructor
Definition: memory.hh:31
ObjectType * getEntityObject(const FactoryType &factory, int level, EntityImp *)
i.e. return pointer to Entity
Definition: memory.hh:49
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:237
void assign(T &dst, const T &src, bool mask)
masked Simd assignment (scalar version)
Definition: simd.hh:447