⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 allocmem.c

📁 基于单片机的 snmp协议解析的一些原代码 给有用的 同行
💻 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 + -