test.c

来自「操作系统的内存管理」· C语言 代码 · 共 35 行

C
35
字号
//测试函数
#include "memory.h"
#include <time.h>
#include <conio.h> 
void main()
{  int i;
   char *ch[200];
   int randnum;
  struct list *tmplist;
   //my_test_para mytest[N];
  //初始话一整块全为空闲区
  mymemory.memorybase = memoryarray;
  mymemory.memorysize = TOTALMEMORY;
  mymemory.myalloclist = NULL;
  mymemory.myfreelist = (struct list *)memoryarray;
  mymemory.myfreelist->size = TOTALMEMORY - sizeof(struct list *);
  mymemory.myfreelist->next = NULL;
  mymemory.myfreelist->pre = NULL;
  //初始化完毕
  printf("test begin...\n");
  srand((unsigned)time(NULL));
  for(i=0;i<200;i++)
  {  
	
	randnum = rand()%500+1;
    ch[i] = myalloc(randnum);
	randnum = rand()%2;
	if(randnum==1) 
	{
		randnum = rand()%(i+1);
		myfree(ch[randnum]);
	}
  }
  getch();
}

⌨️ 快捷键说明

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