1 Star 0 Fork 4

zjx2599/基于c语言的内存池实现

forked from 谭旭佳/memory pool 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
MemPool.h 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
txj 提交于 2021-08-22 19:15 . mempool
#ifndef _MEMPOOL_H
#define _MEMPOOL_H
#include "pch.h"
/********************结构体定义**************************/
typedef struct MemPoolCfg
{
unsigned int MaxMemPools; /*系统当中最大的内存池个数--目前为1500*/
}tMemPoolCfg;
/*定义链表结构-用来将内存池当中的所有内存块链接起来*/
typedef struct CRU_SLL_NODE {
unsigned char *pNext;
}tCRU_SLL_NODE;
typedef struct CRU_SLL {
unsigned char *pu1Base;
unsigned char *pu1Head;
} tCRU_SLL;
/*以下结构体用来记录内存池的一些具体信息*/
typedef struct MEM_FREE_POOL_REC {
unsigned int Size;
unsigned int UnitsCount;
unsigned int FreeUnitsCount;
unsigned char *pu1ActualBase;
unsigned char *pu1StartAddr;
unsigned char *pu1EndAddr;
tCRU_SLL BufList;
}tMemFreePoolRec;
/***********************************一些宏定义***************************/
#define POOL_MEM_CALLOC(s,c,t) (t *)calloc(s, c)
#define BUDDY_MEM_FREE(p) free(p)
#define POOL_MEM_FREE(p) free(p)
#define MEM_SUCCESS 0
#define MEM_OK_BUT_NOT_ALIGNED 1
#define MEM_FAILURE (unsigned int) (~0UL)
#define MEM_ALIGN_BYTE (sizeof(unsigned long) - 1)
#define MEM_ALIGN ((~0UL) & ~(unsigned long)(sizeof(unsigned long) - 1))
/**************************函数声明*******************************/
unsigned int MemInitMemPool(tMemPoolCfg *pMemPoolCfg);
unsigned int MemCreateMemPool(unsigned int BlockSize, unsigned int NumberOfBlocks, unsigned int *pPoolId);
unsigned int MemAllocateMemBlock(unsigned int PoolId, unsigned char **ppu1Block);
unsigned int MemReleaseMemBlock(unsigned int PoolId, unsigned char *pu1Block);
unsigned int MemDeleteMemPool(unsigned int PoolId);
unsigned int GetBlockSize(unsigned int PoolId);
unsigned int GetUnitsCount(unsigned int PoolId);
unsigned int GetFreeUnitsCount(unsigned int PoolId);
#endif
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/zjx2599/c98.git
git@gitee.com:zjx2599/c98.git
zjx2599
c98
基于c语言的内存池实现
master

搜索帮助