c++内存池
来源:互联网 发布:炒房洪流中的数据后门 编辑:程序博客网 时间:2024/06/02 07:30
#include<list>
template<class T , int nBlockSize = 512>
class CMemoryPool
{
public:
CMemoryPool()
{
AllocBlock();
}
~CMemoryPool()
{
std::list<T*>::iterator it;
for(it = m_lstLink.begin(); it != m_lstLink.end(); it++)
{
T *pBlock = *it;
if(pBlock != NULL)
{
delete []pBlock;
pBlock = NULL;
}
}
}
T* Alloc()
{
T *pBuffer = NULL;
if(m_lstFree.size() == 0)
{
AllocBlock();
}
pBuffer = m_lstFree.front();
m_lstFree.pop_front();
return pBuffer;
}
void Release(T *pData)
{
memset(pData,0,sizeof(T));
m_lstFree.push_front(pData);
}
private:
void AllocBlock()
{
T *pBlock = new T[nBlockSize];
m_lstLink.push_back(pBlock);
for(int i = 0; i < nBlockSize; i++)
{
m_lstFree.push_back(pBlock++);
}
}
std::list<T*> m_lstFree;
std::list<T*> m_lstLink;
};
- C 实现内存池
- c实现的内存池
- C语言实现内存池
- C语言实现内存池
- c语言内存池实现
- 简易C\C++内存池
- 简易C\C++内存池
- linux c 实现内存池
- C 内存池的实现
- c内存
- C内存
- C 内存
- C-内存
- 常用内存块及内存池实现2(C++)
- 【C/C++】内存对齐
- 【c/c++】内存地址
- 内存池的简单试验(C++)
- 内存池的简单试验(C++)
- HTML5 文件操作API
- Android Fragments 详细使用
- Android中使用SAX来解析XML
- Android 使用AudioRecord 录音只有噪音
- 黑马程序员_Map集合
- c++内存池
- 设计模式19:职责链模式【行为型】
- C语言程序设计语言统计字符出现的次数
- time_t 与字符串之间的相互转换
- 游戏开发应该掌握的知识
- 投票协议:发送和接收
- Cocos2D-iPhone 安装及简单介绍
- 然后应将此 <customErrors> 标记的“mode”属性设置为“Off”。解决方案
- 产品设计“九步法”