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