QDP++
qdp_pool_allocator.h
Go to the documentation of this file.
1// -*- C++ -*-
2
7
8#ifndef QDP_POOL_ALLOCATOR
9#define QDP_POOL_ALLOCATOR
10
11
12#define TBB_PREVIEW_MEMORY_POOL 1
13#include "tbb/memory_pool.h"
14
15#include "qdp_singleton.h"
16namespace QDP
17{
18 namespace Allocator {
19
20 // A Descrptor contains the start block and the number of blocks
21 // In an object
22 // The idea is that when we allocate n_blocks, they will be contiguous
23 // so we can just note the start, and the number
24 // and then pop them off the end of the free list.
25 // When we return to the pool we can just add back the blocks.
26
27 struct PoolMemInfo {
28 size_t Size;
29 unsigned char* Unaligned;
30 };
31
32 using PoolMapT = std::map<void *,PoolMemInfo>;
33
34
35 // Quick and Dirty Pool ALlocator
36 class QDPPoolAllocator {
37 private:
38 // Disallow Copies
39 QDPPoolAllocator(const QDPPoolAllocator& c) {}
40
41 // Disallow assignments (copies by another name)
42 void operator=(const QDPPoolAllocator& c) {}
43
44 // Disallow creation / destruction by anyone except
45 // the singleton CreateUsingNew policy which is a "friend"
46 // I don't like friends but this follows Alexandrescu's advice
47 // on p154 of Modern C++ Design (A. Alexandrescu)
48 QDPPoolAllocator(void);
49 ~QDPPoolAllocator();
51 friend class QDP::CreateStatic<QDP::Allocator::QDPPoolAllocator>;
52 public:
53 // Init -- has to
54 void init(size_t PoolSizeInMB);
55
56 void* allocate(size_t n_bytes, const MemoryPoolHint& mem_pool_hint);
57 void free(void *mem);
58
59 // Memory debugging Interface
60 void pushFunc(const char *func, int line);
61 void popFunc(void);
62 void dump();
63
64
65 private:
66 size_t _PoolSize;
67 unsigned char* _MyMem;
68 tbb::fixed_pool* _LargePool;
69 PoolMapT theAllocMap;
70
71 };
72
73
74
75
76 } // namespace Allocator
77} // namespace QDP
78
79#endif
void * allocate(size_t n_bytes, const MemoryPoolHint &mem_pool_hint)
void pushFunc(const char *func, int line)
std::map< void *, PoolMemInfo > PoolMapT
Yet another random number generator.
Singleton support.