用C语言实现一块内存的管理操作,包括申请、释放、替换等操作
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
char memory[2000];
struct block{
size_t size; //区块大小
int free; //是否已使用
struct block *next; //指向下一个区块
};
struct block *freeList=(void *)memory;
void init()
{
freeList->size=2000-sizeof(struct block); //可用空间大小
freeList->free=1; //1:空闲 0:使用
freeList->next=NULL; //指向空
}
void split(struct block *fitting_slot,size_t size)
{
struct block *new=(void*)(fitting_slot+size+sizeof(struct block)); //定义new的地址
new->size=(fitting_slot->size)-size-sizeof(struct block); //定义s