代码拉取完成,页面将自动刷新
#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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。