-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMemoryPool.h
More file actions
48 lines (40 loc) · 744 Bytes
/
Copy pathMemoryPool.h
File metadata and controls
48 lines (40 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
template<typename T>
class CMemoryPool
{
public:
CMemoryPool(int nInitSize, int nGrowSize);
~CMemoryPool();
public:
T* Alloc();
void Free(T* data);
private:
struct MemoryBlock
{
int nSize;
int nFreeSize;
T* data; //自动调整永远指向可用的
MemoryBlock* pNestBlock;
MemoryBlock(int _nSize);
~MemoryBlock(){}
T* Alloc();
void Free(T* data);
static void* operator new(size_t, size_t nTypeSize, size_t nSize)
{
return ::operator new(sizeof(MemoryBlock) + (nTypeSize > 4 ? nTypeSize : 4) * nSize);
}
/*static void operator delete(void* data)
{
::operator delete(p);
}*/
};
private:
CCriticalSection m_csMemoryBlock;
MemoryBlock* m_pBlock;
int m_nGrowSize;
};
struct st
{
int a;
char b;
int c;
};