1 Star 0 Fork 0

sun152121/cpp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MemPool.h 896 Bytes
一键复制 编辑 原始数据 按行查看 历史
sun152121 提交于 2016-05-16 20:22 +08:00 . init commit
#ifndef __H_MEMPOOL_
#define __H_MEMPOOL__
#include <mutex>
//#pragma pack(1)
#define ALIGN 8
#define align(a,n) \
((a + n - 1) & (~(n - 1)))
//4KB以下的内存分配使用内存池
#define MAX_MEM (4 * 1024)
#define MAX_HEAD (MAX_MEM >> 3)
struct _BlockHead;
struct _MemBlock;
typedef _BlockHead BlockHead;
typedef _MemBlock MemBlock;
struct _BlockHead {
int m_free_count;
MemBlock* m_free_list;
std::mutex _mutex;
};
struct _MemBlock {
MemBlock* m_next;
BlockHead* m_head;
char m_data[0];
};
class MemPool {
public:
static MemPool* getInstance();
void* _malloc(int n);
void* _calloc(int n);
void _free(void* p);
private:
MemPool();
~MemPool();
BlockHead m_block_head[MAX_HEAD];
};
//static struct helper{
// helper(){
// MemPool* pool = MemPool::getInstance();
// }
// ~helper(){
// }
//} _obj;
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/appcode/cpp.git
git@gitee.com:appcode/cpp.git
appcode
cpp
cpp
master

搜索帮助