allocmem.c
来自「基于单片机的 snmp协议解析的一些原代码 给有用的 同行」· C语言 代码 · 共 73 行
C
73 行
#include "allocmem.h"
ALLOC_MEM_struct *firstAllocMem;
void AllocMemInit(void)
{
firstAllocMem = NULL;
return;
}
int AllocMemAdd(void *theNewPtr)
{
ALLOC_MEM_struct *cur;
ALLOC_MEM_struct *new_ptr;
int err;
err = 0;
if (firstAllocMem == NULL)
{
firstAllocMem = (ALLOC_MEM_struct *)malloc(sizeof(ALLOC_MEM_struct));
if (firstAllocMem == NULL)
{
err = 1;
}
else
{
firstAllocMem->Alloc = theNewPtr;
firstAllocMem->next = NULL;
}
}
else
{
new_ptr = (ALLOC_MEM_struct *)malloc(sizeof(ALLOC_MEM_struct));
if (new_ptr == NULL)
{
err = 1;
}
else
{
/* assign the allocated pointer */
new_ptr->Alloc = theNewPtr;
/* insert new pointer on the list */
cur = firstAllocMem;
while (cur->next != NULL)
{
cur = cur->next;
}
cur->next = new_ptr;
new_ptr->next = NULL;
}
}
return err;
}
void AllocMemDestroy(void)
{
ALLOC_MEM_struct *temp, *cur;
cur = firstAllocMem;
while (cur != NULL)
{
temp = cur;
cur = cur->next;
free(temp->Alloc);
free(temp);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?