VAPOR3 3.9.4
BlkMemMgr.h
Go to the documentation of this file.
1//
2// $Id$
3//
4
5#ifndef _BlkMemMgr_h_
6#define _BlkMemMgr_h_
7
8#include <vapor/MyBase.h>
9
10namespace VAPoR {
11
12//
25//
26class BlkMemMgr : public Wasp::MyBase {
27public:
29 //
31 //
33 virtual ~BlkMemMgr();
34
36 //
41 //
42 void *Alloc(size_t num_blks, bool fill = false);
43
45 //
49 void FreeMem(void *ptr);
50
52 //
66 //
67 static int RequestMemSize(size_t blk_size, size_t num_blks, bool page_aligned = true);
68
69 static size_t GetBlkSize() { return (_blk_size); }
70
71private:
72 typedef struct {
73 size_t _nfree; // number of contiguous free blocks
74 size_t _nused; // number of contiguous used blocks
75 void * _blk; // pointer to first free/used block
76 } _mem_allocation_t;
77
78 static vector<vector<_mem_allocation_t>> _mem_regions;
79 static vector<size_t> _mem_region_sizes; // size of mem in blocks
80 static vector<unsigned char *> _blks; // memory pool
81
82 static size_t _mem_size_max_req; // max requested size of mem in blocks
83 static bool _page_aligned_req; // requested page align memory
84 static size_t _blk_size_req; // requested size of block in bytes
85
86 static size_t _mem_size_max; // max size of mem in blocks
87 static bool _page_aligned; // page align memory
88 static size_t _blk_size; // size of block in bytes
89
90 static int _ref_count; // # instances of object.
91
92 static int _Reinit(size_t n);
93};
94}; // namespace VAPoR
95
96#endif // _BlkMemMgr_h_
The Wasp BlkMemMgr class.
Definition: BlkMemMgr.h:26
static int RequestMemSize(size_t blk_size, size_t num_blks, bool page_aligned=true)
Set the size of the memory pool used by the memory allocator.
virtual ~BlkMemMgr()
BlkMemMgr()
Initialize a memory allocator.
static size_t GetBlkSize()
Definition: BlkMemMgr.h:69
void FreeMem(void *ptr)
Free memory.
void * Alloc(size_t num_blks, bool fill=false)
Alloc space from memory pool.
Wasp base class.
Definition: MyBase.h:67