1 #ifndef DUNE_FEM_ARRAYALLOCATOR_HH 2 #define DUNE_FEM_ARRAYALLOCATOR_HH 14 template<
class Traits >
17 typename Traits :: ArrayAllocatorType >
21 < ThisType,
typename Traits :: ArrayAllocatorType >
37 ElementPtrType &array )
const 39 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
asImp().
allocate( size, array ) );
42 inline void free ( ElementPtrType &array )
const 44 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(
asImp().
free( array ) );
49 ElementPtrType &array )
const 51 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
55 inline void reserve (
unsigned int newSize,
56 ElementPtrType &array )
const 58 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
64 template<
class Traits >
72 using BaseType :: allocate;
73 using BaseType :: free;
82 ElementPtrType &array )
const 84 ElementPtrType newArray;
87 const unsigned int copySize =
std :: min( oldSize, newSize );
88 for(
unsigned int i = 0; i < copySize; ++i )
89 newArray[ i ] = array[ i ];
96 inline void reserve (
unsigned int newSize,
97 ElementPtrType &array )
const 102 template<
class Element >
105 template<
class Element >
110 #ifndef USE_CARRAYALLOCATOR 111 template<
class Element >
116 template<
class Element >
123 template<
class Element >
133 template<
class Element >
147 ElementPtrType &array )
const 151 array =
new ElementType[ size ];
152 assert( array != 0 );
158 inline void free ( ElementPtrType &array )
const 169 template<
class Element >
180 template<
class Element >
194 ElementPtrType &array )
const 199 assert( array != 0 );
204 inline void free ( ElementPtrType &array )
const 208 std :: free( array );
214 unsigned int newSize,
215 ElementPtrType &array )
const 219 std :: free( array );
223 array = (
ElementPtrType)realloc( array, newSize *
sizeof( ElementType ) );
229 template<
class Element,
template<
class >
class WrappedArrayAllocator >
230 class ArrayOverAllocator;
233 template<
class Element,
template<
class >
class WrappedArrayAllocator >
234 class ArrayOverAllocatorElementPointer
236 typedef ArrayOverAllocatorElementPointer< Element, WrappedArrayAllocator >
239 friend class ArrayOverAllocator< Element, WrappedArrayAllocator >;
244 typedef WrappedArrayAllocator< ElementType > WrappedArrayAllocatorType;
246 typedef typename WrappedArrayAllocatorType :: ElementPtrType
ElementPtrType;
253 inline ArrayOverAllocatorElementPointer ()
258 inline ArrayOverAllocatorElementPointer (
const ElementPtrType ptr,
259 const unsigned int size )
264 inline ArrayOverAllocatorElementPointer (
const ThisType &other )
265 : ptr_( other.ptr_ ),
269 inline ThisType &operator= (
const ThisType &other )
275 inline operator const ElementType * ()
const 277 return (ElementType *)ptr_;
280 inline operator ElementType * ()
const 282 return (ElementType *)ptr_;
290 inline ElementType &operator[] (
const unsigned int index )
const 292 assert( index < size_ );
293 return ptr_[ index ];
298 template<
class Element,
template<
class >
class WrappedArrayAllocator >
299 struct ArrayOverAllocatorTraits
303 typedef WrappedArrayAllocator< ElementType > WrappedArrayAllocatorType;
305 typedef ArrayOverAllocatorElementPointer
309 typedef ArrayOverAllocator< ElementType, WrappedArrayAllocator >
314 template<
class Element,
template<
class >
class WrappedArrayAllocator >
315 class ArrayOverAllocator
317 < ArrayOverAllocatorTraits< Element, WrappedArrayAllocator > >
319 typedef ArrayOverAllocator< Element, WrappedArrayAllocator >
ThisType;
320 typedef ArrayOverAllocatorTraits< Element, WrappedArrayAllocator >
Traits;
328 typedef typename Traits :: WrappedArrayAllocatorType
329 WrappedArrayAllocatorType;
332 WrappedArrayAllocatorType allocator_;
333 unsigned int memFactor_;
336 inline explicit ArrayOverAllocator (
const unsigned int memFactor = 1152 )
338 memFactor_( memFactor )
341 inline explicit ArrayOverAllocator (
const double memFactor )
343 memFactor_( (
int)(memFactor * 1024) )
348 ArrayOverAllocator (
const WrappedArrayAllocatorType &allocator,
349 const unsigned int memFactor = 1152 )
350 : allocator_( allocator ),
351 memFactor_( memFactor )
354 inline ArrayOverAllocator (
const WrappedArrayAllocatorType &allocator,
355 const double memFactor )
356 : allocator_( allocator ),
357 memFactor_( (
int)(memFactor * 1024) )
360 inline ArrayOverAllocator (
const ThisType &other )
361 : allocator_( other.allocator_ ),
362 memFactor_( other.memFactor_ )
365 inline ThisType &operator= (
const ThisType &other )
367 allocator_ = other.allocator_;
368 memFactor_ = other.memFactor_;
371 inline void allocate (
unsigned int size,
372 ElementPtrType &array )
const 374 array.size_ = (size * memFactor_) / 1024;
375 allocator_.allocate( array.size_, array.ptr_ );
378 inline void free ( ElementPtrType &array )
const 380 allocator_.free( array.ptr_ );
384 inline void reallocate (
unsigned int oldSize,
385 unsigned int newSize,
386 ElementPtrType &array )
const 388 const unsigned int newAllocSize = (newSize * memFactor_) / 1024;
389 if( array.size_ < newSize )
390 reserve( newAllocSize, array );
393 inline void reserve (
unsigned int newSize,
394 ElementPtrType &array )
const 396 if( newSize > array.size_ )
398 allocator_.reallocate( array.size_, newSize, array.ptr_ );
399 array.size_ = newSize;
405 template<
class Element >
406 class DefaultArrayOverAllocator
407 :
public ArrayOverAllocator< Element, DefaultArrayAllocator >
415 #endif // #ifndef DUNE_FEM_ARRAYALLOCATOR_HH Element * ElementPtrType
Definition: arrayallocator.hh:127
static constexpr T min(T a)
Definition: utility.hh:81
void free(ElementPtrType &array) const
Definition: arrayallocator.hh:204
Element ElementType
Definition: arrayallocator.hh:126
Definition: arrayallocator.hh:65
void free(ElementPtrType &array) const
Definition: arrayallocator.hh:42
void allocate(unsigned int size, ElementPtrType &array) const
Definition: arrayallocator.hh:36
StandardArrayAllocator< ElementType > ArrayAllocatorType
Definition: arrayallocator.hh:129
Traits::ElementType ElementType
Definition: arrayallocator.hh:29
Traits::ElementPtrType ElementPtrType
Definition: arrayallocator.hh:77
void reallocate(unsigned int oldSize, unsigned int newSize, ElementPtrType &array) const
Definition: arrayallocator.hh:80
Traits::ElementType ElementType
Definition: arrayallocator.hh:76
const Implementation & asImp() const
Definition: bartonnackmaninterface.hh:37
Element ElementType
Definition: arrayallocator.hh:172
Definition: arrayallocator.hh:124
Element * ElementPtrType
Definition: arrayallocator.hh:174
void allocate(unsigned int size, ElementPtrType &array) const
Definition: arrayallocator.hh:193
void reallocate(unsigned int oldSize, unsigned int newSize, ElementPtrType &array) const
Definition: arrayallocator.hh:47
void reserve(unsigned int newSize, ElementPtrType &array) const
Definition: arrayallocator.hh:55
Traits::ElementPtrType ElementPtrType
Definition: arrayallocator.hh:190
Traits::ElementPtrType ElementPtrType
Definition: arrayallocator.hh:30
Definition: coordinate.hh:4
Traits::ElementType ElementType
Definition: arrayallocator.hh:142
Double operator*(const Double &a, const Double &b)
Definition: double.hh:495
Definition: arrayallocator.hh:170
Definition: arrayallocator.hh:103
Traits::ArrayAllocatorType ArrayAllocatorType
Definition: arrayallocator.hh:25
void reallocate(unsigned int oldSize, unsigned int newSize, ElementPtrType &array) const
Definition: arrayallocator.hh:213
void reserve(unsigned int newSize, ElementPtrType &array) const
Definition: arrayallocator.hh:96
void free(ElementPtrType &array) const
Definition: arrayallocator.hh:158
Traits::ElementPtrType ElementPtrType
Definition: arrayallocator.hh:143
void allocate(unsigned int size, ElementPtrType &array) const
Definition: arrayallocator.hh:146
CArrayAllocator< ElementType > ArrayAllocatorType
Definition: arrayallocator.hh:176
ThisType ArrayAllocatorInterfaceType
Definition: arrayallocator.hh:27
Definition: arrayallocator.hh:15
Definition: bartonnackmaninterface.hh:15
Traits::Element ElementType
Definition: arrayallocator.hh:189
Definition: arrayallocator.hh:112
Definition: arrayallocator.hh:106