?? data.cpp
字號:
// Data.cpp: implementation of the Data class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Lin.h"
#include "Data.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Data::Data()
{
}
Data::~Data()
{
}
//DEL JobList Data::JobAdd()
//DEL {
//DEL
//DEL }
JobList Data::JobAdd(CString Job_ID, UINT Job_SIZE) //添加作業(yè),存于作業(yè)鏈表中
{
JobList job_temp=new JOB;
job_temp->ID=Job_ID;
job_temp->MemSize=Job_SIZE;
job_temp->next=job_list;
job_list=job_temp;
return job_list;
}
JobList Data::Delet(UINT nID,UINT &FirAddr,UINT &Size) // 刪去作業(yè)鏈表中指定的作業(yè)
{
UINT i;
JobList temp,del=NULL;
temp=job_list;
if(nID==1)
{
del=temp;
job_list=job_list->next;
}
else
{
for(i=2;i<nID;i++)
{
temp=temp->next;
}
del=temp->next;
temp->next=del->next;
}
FirAddr=del->First_Addr;
Size=del->MemSize;
delete(del);
return job_list;
}
//DEL MemList Data::MemASSIGN(UINT SIZE)
//DEL {
//DEL MemList temp;
//DEL temp=mem_list;
//DEL while(temp!=NULL&&temp->Last_Addr-temp->First_Addr<SIZE)
//DEL {
//DEL temp=temp->tail;
//DEL }
//DEL if(temp!=NULL)
//DEL {
//DEL temp->First_Addr=temp->First_Addr+SIZE;
//DEL }
//DEL return mem_list;
//DEL }
MemList Data::MemRECLAIM(UINT First_Addr, UINT Size) // 內(nèi)存回收的函數(shù)
{
MemList temp;
UINT last_addr;
// int flag=0;
last_addr=First_Addr+Size;
temp=mem_list;
if(temp->First_Addr==last_addr) temp->First_Addr=First_Addr; // 回收分區(qū)位于表頭且有后接分區(qū)
else if(temp->First_Addr>last_addr) // 回收分區(qū)位于鏈表表頭且無相鄰分區(qū)
{
MemList block;
block=new MEM;
block->First_Addr=First_Addr;
block->Last_Addr=last_addr;
block->prior=temp->prior;
block->tail=temp;
temp->prior=block;
mem_list=block;
}
else
{
MemList p;
while(temp!=NULL&&last_addr>temp->First_Addr)
{
p=temp;
temp=temp->tail;
}
if(temp==NULL) // 回收分區(qū)處在鏈表表尾且無相鄰分區(qū)
{
MemList block;
block=new MEM;
block->First_Addr=First_Addr;
block->Last_Addr=last_addr;
block->prior=p;
block->tail=temp;
// temp->prior=block;
block->prior->tail=block;
}
else if(temp->First_Addr==last_addr&&temp->prior->Last_Addr==First_Addr)
{ //回收分區(qū)與上下空閑區(qū)相鄰的情況
temp->prior->Last_Addr=temp->Last_Addr;
temp->prior->tail=temp->tail;
if(temp->tail!=NULL) //防止出現(xiàn)NULL->prior的情況
{
temp->tail->prior=temp->prior;
}
delete(temp);
}
else if(temp->First_Addr==last_addr) // 回收分區(qū)與后一分區(qū)相鄰
{
temp->First_Addr=First_Addr;
}
else if(temp->prior->Last_Addr==First_Addr) // 回收分區(qū)與前一分區(qū)相鄰
{
temp->prior->Last_Addr=last_addr;
}
else // 回收分區(qū)位于鏈表表尾且無相鄰分區(qū)
{
MemList block;
block=new MEM;
block->First_Addr=First_Addr;
block->Last_Addr=last_addr;
block->prior=temp->prior;
block->tail=temp;
temp->prior=block;
block->prior->tail=block;
}
}
return mem_list;
}
MemList Data::MemInit() //內(nèi)存空間的初始化
{
MemList temp;
temp=new MEM;
temp->First_Addr=0;
temp->Last_Addr=600;
temp->prior=NULL;
temp->tail=NULL;
mem_list=temp;
return mem_list;
}
//DEL UINT Data::MostSize(MemList mem_list)
//DEL {
//DEL UINT MostSize;
//DEL MemList temp;
//DEL temp=mem_list;
//DEL while(temp!=NULL)
//DEL {
//DEL if(MostSize<temp->Last_Addr-temp->First_Addr)
//DEL MostSize=temp->Last_Addr-temp->First_Addr;
//DEL temp=temp->tail;
//DEL }
//DEL return MostSize;
//DEL }
void Data::Fill_Mem(UINT Fir_Addr) //向成功獲得內(nèi)存分配的作業(yè)存入其首地址信息
{
job_list->First_Addr=Fir_Addr;
}
UINT Data::MemAssign(UINT SIZE)
{
MemList temp;
UINT Fir_Addr;
temp=mem_list;
while(temp!=NULL&&temp->Last_Addr-temp->First_Addr<SIZE)
{
temp=temp->tail;
}
if(temp->Last_Addr-temp->First_Addr>=SIZE)
{
Fir_Addr=temp->First_Addr;
temp->First_Addr=temp->First_Addr+SIZE;
}
return Fir_Addr;
}
JobList Data::JobInit() //作業(yè)鏈表的初始化
{
// JobList temp;
job_list=NULL;
return job_list;
}
UINT Data::MostSize() //探測空閑鏈表中的最大空閑塊大小
{
UINT MostSize=0;
MemList temp;
temp=mem_list;
while(temp!=NULL)
{
if(MostSize<temp->Last_Addr-temp->First_Addr)
MostSize=temp->Last_Addr-temp->First_Addr;
temp=temp->tail;
}
return MostSize;
}
//DEL void Data::ShowMemList()
//DEL {
//DEL
//DEL }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -