1 Star 0 Fork 68

K./socket

forked from beykery/cocosocket 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
MemoryPool.h 843 Bytes
一键复制 编辑 原始数据 按行查看 历史
beykery 提交于 2014-01-09 19:39 . fdf
#ifndef MEMORYPOOL_H
#define MEMORYPOOL_H
#include <stdio.h>
#include <stdlib.h>
struct MemoryList {
void * memory;
MemoryList * next;
};
class MemoryPool {
public:
MemoryPool(unsigned int size, unsigned int increase = 64);
~MemoryPool();
void * Alloc();
void Free(void *m);
private:
unsigned int m_size;
unsigned int m_increase;
MemoryList * m_memory_list_header;
MemoryList * m_handle;
};
#define REGISTER_MEMORYPOOL(PoolNameSpace, ClassName, IncreaseNum) \
namespace PoolNameSpace\
{\
MemoryPool g_##ClassName##_mem_pool(sizeof(ClassName), IncreaseNum);\
}\
void *ClassName::operator new(size_t size)\
{\
void *mem = PoolNameSpace::g_##ClassName##_mem_pool.Alloc();\
return mem;\
}\
void ClassName::operator delete(void *m)\
{\
PoolNameSpace::g_##ClassName##_mem_pool.Free(m);\
}
#endif
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/stanjo/socket.git
[email protected]:stanjo/socket.git
stanjo
socket
socket
master

搜索帮助