#pragma once
#include <vector>
#include "Poco\Mutex.h"
template<class T>
class CFramePool
{
public:
CFramePool(int preAlloc, int maxAlloc = 0);
~CFramePool();
/**
@des
申请一个T
*/
T* get();
/**
@des
释放一个T
*/
void release(T* ptr);
/**
@des
获取池的大小
*/
int allocated() const;
/**
@des
可用个数
*/
int available() const;
private:
CFramePool(); //缺省构造??
CFramePool(CFramePool&); //默认复制构造
CFramePool& operator =(const CFramePool&); //默认赋值
Poco::FastMutex m_MtxBlocks;
std::vector<T*> m_vecBlocks;
int m_nAllocated;
int m_nMaxAlloc;
};
//函数定义
template<class T>
CFramePool<T>::CFramePool(int preAlloc, int maxAlloc/* = 0*/) :
m_nMaxAlloc(maxAlloc),
m_nAllocated(preAlloc)
{
m_vecBlocks.clear();
for (int i = 0; i < preAlloc; i++)
{
T* ptr = new T;
m_vecBlocks.push_back(ptr);
}
}
template<class T>
CFramePool<
内存池模板 参考Poco库 简单易懂
最新推荐文章于 2023-09-16 16:17:38 发布