兰州网站制作成都wordpress默认登陆地址
2026/4/6 5:57:46 网站建设 项目流程
兰州网站制作成都,wordpress默认登陆地址,网站网页设计哪个好,郑州大学第一附属医院1. 要求建立空闲块构成的链表#xff0c;每个块包含该块的字节数和指向链表中下个块的指针。从每个块起始处存放它们。要分配指定大小的块时#xff0c;采用最先适应算法#xff0c;取出所需要的块#xff0c;接着更新链表。该块被释放时#xff0c;把该块添加到链表的尾部…1. 要求建立空闲块构成的链表每个块包含该块的字节数和指向链表中下个块的指针。从每个块起始处存放它们。要分配指定大小的块时采用最先适应算法取出所需要的块接着更新链表。该块被释放时把该块添加到链表的尾部。2. C程序#include stdlib.h #include sys/mman.h #include stdio.h #define WSIZE 4 /* word size (bytes) */ #define DSIZE 8 /* double word size (bytes) */ #define OVERHEAD 12 /* overhead of header and footer (bytes) */ struct segment { int length; struct segment *link; } ; struct segment *head; /* 声明结构函数allocblock()和无值型函数dealloc() */ struct segment *allocblock(int x); void print(struct segment *phead); struct segment *find_fit(int x); void dealloc(struct segment *blo); int main() { int size; struct segment *freelist,*p,*q,*block1; size100; headNULL; freelist(struct segment *)mmap( NULL,4096,PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,-1,0 ); if(freelistMAP_FAILED) { printf(mmap faile); } /* 建立链表 */ freelist-lengthsize; freelist-linkNULL; headfreelist; pheadsizeOVERHEAD; p-length200; freelist-linkp; p-linkNULL; qpp-lengthOVERHEAD; q-length300; p-linkq; q-linkNULL; printf(before allocblock:\n); print(head); size120; block1allocblock(size); // 分配一个size大小块block1 if (block1 NULL) { perror(allocblock faile); exit(1); } printf(The length of allocated block is %d\n,block1-length); printf(after allocblock:\n); print(head); dealloc(block1); // 释放block1 printf(after dealloc:\n); print(head); return 0; } struct segment *allocblock(int x) { int i,temp; struct segment *bp; if (x0) return NULL; else if (xDSIZE) xOVERHEAD WSIZE; else x((x(OVERHEAD)(DSIZE-1))/DSIZE)*DSIZE; if((bpfind_fit(x))!NULL){ return bp; } else return NULL; } struct segment *find_fit(int x){ struct segment *m,*n,*r; int temp; mhead; if(xhead-length){ if(((head-length)-x)2*DSIZE) headhead-link; else{ tempm-length; m-lengthx; headmx12; head-lengthtemp-x-12; head-linkm-link; } } else{ while(xm-length){ nm; mm-link; if (mNULL) break; } if (m!NULL){ if(((m-length)-x)2*DSIZE) n-linkm-link; else{ tempm-length; m-lengthx; rmx12; r-lengthtemp-x-12; n-linkr; r-linkm-link; } } else return NULL; } return m; } void print(struct segment *phead) { struct segment *p; pphead; while (p!NULL){ printf(%d\n,p-length); pp-link ; } } void dealloc(struct segment *blo) { struct segment *p; phead; while(p-link!NULL) pp-link; p-link blo; blo-link NULL; }3. 运行结果before allocblock:100200300The length of allocated block is 136after allocblock:10052300after dealloc:10052300136

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询