VAPoR  0.1
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 
10 namespace VAPoR {
11 
12 //
25 //
26 class BlkMemMgr : public VetsUtil::MyBase {
27 
28 public:
30  //
32  //
33  BlkMemMgr();
34  virtual ~BlkMemMgr();
35 
37  //
42  //
43  void *Alloc(size_t num_blks, bool fill = false);
44 
46  //
50  void FreeMem(void *ptr);
51 
53  //
67  //
68  static int RequestMemSize(
69  size_t blk_size, size_t num_blks, bool page_aligned = true
70  );
71 
72  static size_t GetBlkSize() {return(_blk_size);}
73 
74 private:
75  typedef struct {
76  size_t _nfree; // number of contiguous free blocks
77  size_t _nused; // number of contiguous used blocks
78  void *_blk; // pointer to first free/used block
79  } _mem_allocation_t;
80 
81  static vector < vector <_mem_allocation_t > > _mem_regions;
82  static vector <size_t> _mem_region_sizes; // size of mem in blocks
83  static vector <unsigned char *> _blks; // memory pool
84 
85  static size_t _mem_size_max_req; // max requested size of mem in blocks
86  static bool _page_aligned_req; // requested page align memory
87  static size_t _blk_size_req; // requested size of block in bytes
88 
89  static size_t _mem_size_max; // max size of mem in blocks
90  static bool _page_aligned; // page align memory
91  static size_t _blk_size; // size of block in bytes
92 
93  static int _ref_count; // # instances of object.
94 
95  static int _Reinit(size_t n);
96 
97 };
98 };
99 
100 #endif // _BlkMemMgr_h_
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.
void * Alloc(size_t num_blks, bool fill=false)
Alloc space from memory pool.
BlkMemMgr()
Initialize a memory allocator.
virtual ~BlkMemMgr()
void FreeMem(void *ptr)
Free memory.
static size_t GetBlkSize()
Definition: BlkMemMgr.h:72
VetsUtil base class.
Definition: MyBase.h:68
The VetsUtil BlkMemMgr class.
Definition: BlkMemMgr.h:26