能力值:
( LV2,RANK:10 )
|
-
-
2 楼
我会说我要顶你嘛
|
能力值:
( LV12,RANK:200 )
|
-
-
3 楼
能给个调用例子么?
PS
/// 好像和模板没啥关系
// template <class T>
class CMemory
#ifndef CXX_MEMPOOL_H
# define CXX_MEMPOOL_H
#include <windows.h>
#include <memory>
#define FAILRST 0
#define SUCCRST 1
#define NUMZERO 0
#define NUMONE 1
#define INTSIZE (sizeof(int))
#define POINTERSIZE (sizeof(void*))
#define MAXMEMLEN 4096*8
#define MEMLENSTEP 8
#define MEMCOUNT (MAXMEMLEN/MEMLENSTEP)
#define GetNextMem(pMem) ((char*)(*(char**)((pMem) - POINTERSIZE)))
#define SetNextMem(pMem, pMemNext) ((*((char**)((pMem) - POINTERSIZE))) = (char*)pMemNext)
#define GetMemSize(pMem) (*(int*)((pMem) - POINTERSIZE - INTSIZE))
#define SetMemSize(pMem, n) (*(int*)((pMem) - POINTERSIZE - INTSIZE) = n)
class CMemMgr
{
public:
void Unlock();
~CMemMgr(void);
/*获取实例指针*/
static CMemMgr *getInstance(void);
/*外部调用者获取内存*/
void *getMem(unsigned int uiMemLen);
/*外部调用者归还内存*/
int rtnMem(char *pMem);
private:
void Lock();
char** m_szMemCtrl; /*用于存放空闲内存的链表数组*/
CMemMgr(void);
CRITICAL_SECTION CriticalSesion;
};
/// 好像和模板没啥关系
// template <class T>
class CMemory
{
public:
void * (operator new)(size_t iSize, LPCSTR lpszFileName, int nLine)
{
void * pMem = CMemMgr::getInstance()->getMem(iSize);
return pMem;
}
void operator delete(void * pMem, LPCSTR lpszFileName, int nLine)
{
CMemMgr::getInstance()->rtnMem((char*)pMem);
}
void * (operator new[])(size_t iSize, LPCSTR lpszFileName, int nLine)
{
void * pMem = CMemMgr::getInstance()->getMem(iSize);
return pMem;
}
void operator delete[](void * pMem, LPCSTR lpszFileName, int nLine)
{
CMemMgr::getInstance()->rtnMem((char*)pMem);
}
void *operator new( size_t iSize)
{
void * pMem = CMemMgr::getInstance()->getMem(iSize);
return pMem;
}
void *operator new[]( size_t iSize)
{
void * pMem = CMemMgr::getInstance()->getMem(iSize);
return pMem;
}
void operator delete( void * pMem, size_t )
{
CMemMgr::getInstance()->rtnMem((char*)pMem);
}
void operator delete[]( void * pMem, size_t )
{
CMemMgr::getInstance()->rtnMem((char*)pMem);
}
};
#endif // #ifndef CXX_MEMPOOL_H
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
不解释 很厉害
|
能力值:
( LV7,RANK:110 )
|
-
-
5 楼
直接继承,呵呵
|
|
|