📄 allocmem.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -