main.c

来自「基于51的动态内存管理」· C语言 代码 · 共 42 行

C
42
字号
#include        "ip51_cs_extr.h"                 /* Common service functions  */
#include        "ip51_dm_extr.h"                 /* Dynamic memory functions  */

void main()
{
   unsigned char far  test[0x5000];
   unsigned char far  test1[0x3000];
   
   void *use;
   void *use1;
   void *use2;
   void *use3;
   void *use4;

   xdata IP51_MEMORY_POOL my_memory_pool; //声明一个内存池指针
   xdata IP51_MEMORY_POOL my_memory_pool1; //声明一个内存池指针

   IP51_DMC_Create_Memory_Pool(&my_memory_pool, "wang",
                        test, 0x5000,100);
   IP51_DMC_Create_Memory_Pool(&my_memory_pool1, "wang1",
                        test1, 0x3000,100);


   IP51_DMC_Allocate_Memory(&my_memory_pool, &use,0x1000);
   IP51_DMC_Allocate_Memory(&my_memory_pool, &use1,0x1000);
   IP51_DMC_Allocate_Memory(&my_memory_pool, &use2,0x1000);
   IP51_DMC_Allocate_Memory(&my_memory_pool, &use4,0x1000);
   IP51_DMC_Deallocate_Memory(use1);
   IP51_DMC_Deallocate_Memory(use2);
   //IP51_DMC_Deallocate_Memory(use4);
   
   if(IP51_DMC_Allocate_Memory(&my_memory_pool, &use3,0x2000) == IP51_NO_MEMORY)
   {
      IP51_DMC_Allocate_Memory(&my_memory_pool, &use3,0x1000);
   }

   IP51_DMC_Delete_Memory_Pool(&my_memory_pool);
   IP51_DMC_Allocate_Memory(&my_memory_pool, &use2,0x2000);
   
   while(1);

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?