1 Star 0 Fork 4

谭旭佳/memory pool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.c 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
Xujia Tan 谭旭佳 提交于 2022-11-02 20:01 . 修改
#include "pch.h"
#include <iostream>
#include "MemPool.h"
using namespace std;
static tMemPoolCfg LrMemPoolCfg;
typedef struct A
{
int a;
int b;
}tA;
int main()
{
unsigned int PooId = 0;
unsigned int node = 10;
unsigned int BlockSize = 0;
unsigned int UnitsCount = 0;
unsigned int FreeUnitsCount = 0;
tA *obj1 = NULL;
tA *obj2 = NULL;
tA *obj3 = NULL;
tA *obj4 = NULL;
tA *obj5 = NULL;
/* 内存池全局配置初始化 */
LrMemPoolCfg.MaxMemPools = 1500; /*内存池数量--初始化为1500个*/
if (MemInitMemPool(&LrMemPoolCfg) != MEM_SUCCESS)
{
printf("MemInitMemPool Fails !!!!!!!!!!!!!!!!!!!!!!");
return 1;
}
/*创建一个内存池,这里最多可以创建1500个*/
MemCreateMemPool(sizeof(tA), node, &PooId);
/*根据PooId分配一小块内存*/
MemAllocateMemBlock(PooId, (unsigned char**)&obj1);
MemAllocateMemBlock(PooId, (unsigned char**)&obj2);
MemAllocateMemBlock(PooId, (unsigned char**)&obj3);
MemAllocateMemBlock(PooId, (unsigned char**)&obj4);
MemAllocateMemBlock(PooId, (unsigned char**)&obj5);
/*查看内存池里的信息*/
BlockSize = GetBlockSize(PooId);
UnitsCount = GetUnitsCount(PooId);
FreeUnitsCount = GetFreeUnitsCount(PooId);
/*释放内存块*/
MemReleaseMemBlock(PooId, (unsigned char*)&obj4);
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/tan-xujia/c98.git
git@gitee.com:tan-xujia/c98.git
tan-xujia
c98
memory pool
master

搜索帮助