#ifdef HAVA_CONFIG_H
#include <config.h>
#endif
#include<stdio.h>
#include<stdlib.h>
#define MAPSIZE 100
struct map//store resoure table'struct
{
int m_addr;
int m_size;
}
;
struct map map[MAPSIZE];
//best fit
int BF_malloc(struct map *mp,int size)
{
register int a,s;
/*these var is recommend to be saved in register,so it can be vary fast
*but only if its size is not bigger thar 'int' can be declared as 'register type'
*more over,this var may not be in memory,so you can not use a '&' to get its address
*/
register struct map *bp,*bpp;
for(bp=mp;bp->m_size;bp++)
{
if(bp->m_size >=size)
{
a=bp->m_addr;
s=bp->m_size;
for(bpp=bp;bpp->m_size;bpp++)
{
if(bpp->m_size >=size && bpp->m_size <s)
{
a=bpp->m_addr;
s=bpp->m_size;
bp=bpp;
}
}
bp->m_addr +&#
linux动态异长存储资源分配算法的实现
最新推荐文章于 2024-09-08 16:25:03 发布
这篇博客介绍了如何在Linux环境下实现动态异长存储资源的分配算法,包括最佳适配(Best Fit)和最差适配(Worst Fit)两种方法。通过示例代码展示了内存分配和释放的详细过程,并提供了初始化、显示内存地图和用户交互的功能。
摘要由CSDN通过智能技术生成