NGSolve 5.3
blockalloc.hpp
1#ifndef FILE_BLOCKALLOC
2#define FILE_BLOCKALLOC
3
4/**************************************************************************/
5/* File: blockalloc.hpp */
6/* Author: Joachim Schoeberl */
7/* Date: 19. Apr. 2000 */
8/**************************************************************************/
9
10#include <ngstd.hpp>
11
12namespace ngstd
13{
14
21{
23 unsigned int size;
25 unsigned int blocks;
27 void * freelist;
29 Array<char*> bablocks;
31 int nels;
32public:
34 NGS_DLL_HEADER BlockAllocator (unsigned int asize, unsigned int ablocks = 100);
37
40 /*
41 {
42 nels++;
43 if (!freelist)
44 Alloc2 ();
45
46 void * p = freelist;
47 freelist = *(void**)freelist;
48 return p;
49 }
50 */
51
52
54 NGS_DLL_HEADER void Free (void * p);
55 /*
56 {
57 nels--;
58 *(void**)p = freelist;
59 freelist = p;
60 }
61 */
62
64 int NumElements () { return nels; }
65
66 NGS_DLL_HEADER void Print (ostream * ost) const;
67
68 const MemoryTracer& GetMemoryTracer() const { return mt; }
69
70 void StartMemoryTracing() const
71 {
72 mt.Alloc(bablocks.Size() * size * blocks);
73 }
74
75private:
76 NGS_DLL_HEADER void * Alloc2 ();
77 MemoryTracer mt;
78};
79
80
81}
82
83INLINE void * operator new (size_t /* size */, ngstd::BlockAllocator & ball)
84{
85 return ball.Alloc();
86}
87
88INLINE void operator delete (void * p, ngstd::BlockAllocator & ball)
89{
90 ball.Free (p);
91}
92
93
94
95#endif
Datatype for automatic differentiation.
Definition autodiff.hpp:26
Optimized memory handler.
Definition blockalloc.hpp:21
NGS_DLL_HEADER BlockAllocator(unsigned int asize, unsigned int ablocks=100)
Create BlockAllocator for elements of size asize.
NGS_DLL_HEADER void * Alloc()
Return pointer to new element.
int NumElements()
number of allocated elements
Definition blockalloc.hpp:64
NGS_DLL_HEADER ~BlockAllocator()
Delete all memeory.
NGS_DLL_HEADER void Free(void *p)
Send memory to free-list.
namespace for standard data types and algorithms.
Definition ngstd.hpp:42