Barst  2.0
A server that controls lab hardware.
mem pool.h
1 
3 #ifndef _CPL_MEM_POOL_H_
4 #define _CPL_MEM_POOL_H_
5 
6 
7 #include <Windows.h>
8 #include <vector>
9 
10 typedef struct SMemoryItem
11 {
13  void* pMemory;
15  unsigned long long ullSize;
17  bool bInUse;
18 
19  SMemoryItem()
20  {
21  memset(&pMemory, 0, sizeof(SMemoryItem));
22  }
23 } SMemoryItem;
24 
25 
26 
27 class CMemPool
28 {
29 public:
30  CMemPool(){};
31  ~CMemPool(){};
32 
33  void* PoolAcquire(unsigned long long ullSize) {return malloc((size_t)ullSize);}
34  void PoolRelease(void* pHead) {free(pHead);}
35  void PoolFreeUnused(){};
36 private:
37 
38  //std::vector<SMemoryItem> m_aMemory;
39  //CRITICAL_SECTION m_rPoolSafe;
40 };
41 
42 
44 typedef struct SRingItem
45 {
47  void* pMemory;
49  int nCount;
50 } SRingItem;
51 
52 
53 
58 class CMemRing
59 {
60 public:
62  CMemRing(__int64 ll_size, int nMinElems, int nMaxElems);
63  virtual ~CMemRing();
64 
67  void *GetIndexMemory(int nIdx);
70  void *GetIndexMemoryUnsafe(int nIdx);
72  void ReleaseIndex(int nIdx);
75  void *GetFree(int *pnIdx);
76 
78  const __int64 m_llSize;
80  const int m_nMinElems;
82  const int m_nMaxElems;
83 private:
84  std::vector<SRingItem> m_apMemory; // holds the memory
85  CRITICAL_SECTION m_hMemSafe; // protects access to the memory.
86 };
87 
88 #endif
89 
90 
int nCount
Definition: mem pool.h:49
void * pMemory
Definition: mem pool.h:13
unsigned long long ullSize
Definition: mem pool.h:15
void * pMemory
Definition: mem pool.h:47
bool bInUse
Definition: mem pool.h:17
const int m_nMaxElems
Definition: mem pool.h:82
const __int64 m_llSize
Definition: mem pool.h:78
const int m_nMinElems
Definition: mem pool.h:80