資源簡介
模擬首次適應動態分區存儲管理方案中的內存分配與回收
含源碼
設計文檔
含源碼
設計文檔
代碼片段和文件信息
//?memorry.cpp?:?定義控制臺應用程序的入口點。
//
#include?“stdafx.h“
#include?
#include?
#include?
using?namespace?std;
class?freeBlock
{
public:?int?size;
public:?int?startAdd;
freeBlock()
{
size=0;
startAdd=0;
}
};
class?usedBlock
{
public?:int?size;
public :?int?startAdd;
public :string?process?;
public?:usedBlock()
{
size=0;
startAdd=0;
process=“null“;
}
};
list??FreeBlocks;
list??UsedBlocks;
int?S?=10;
?void?init()
{
int?size?=0;
int?Start=0;
cout<<“請輸入空閑塊的塊數(確認塊數大于0):“< cin>>?size;
for?(int?i=0;i {
cout<<“請輸入空閑塊“< <<“(請確認塊小于最大內存大小256MB):“;
freeBlock?temp?;
cin>>temp.size;
cout<<“===================================“< temp.startAdd=Start;
FreeBlocks.push_back(temp);
Start?+=temp.size;
}
}
bool?allocate()
{
int?Blocksize;
string?process;
cout<<“請輸入進程名稱“< cin>>process;
cout<<“請輸入進程“< cin>>?Blocksize;
cout<<“===================================“< list::iterator?theIterator;
int?t;
for(?theIterator?=?FreeBlocks.begin();?theIterator?!=?FreeBlocks.end();)
{
t?=theIterator->size-Blocksize;
if?(t>=0)
{
if?(t>=S)
{
freeBlock?temp?;
temp.size?=theIterator->size-Blocksize;
temp.startAdd=theIterator->startAdd+Blocksize;
FreeBlocks.push_back(temp);
usedBlock?usedtemp;
usedtemp.size=Blocksize;
usedtemp.process?=process;
usedtemp.startAdd=theIterator->startAdd;
UsedBlocks.push_back(usedtemp);
}
else?{
usedBlock?usedtemp;
usedtemp.size=theIterator->size;
usedtemp.process?=process;
usedtemp.startAdd=theIterator->startAdd;
UsedBlocks.push_back(usedtemp);
}
theIterator=FreeBlocks.erase(theIterator);
return?true;
}
else{theIterator++;}
}
return?false;
}
bool?recycle()
{
string?process;
cout<<“請輸入要回收的進程名稱“< cin>>process;
cout<<“===================================“< list::iterator?theIterator;
for(?theIterator?=?UsedBlocks.begin();?theIterator?!=?UsedBlocks.end();?)
{
if(theIterator->process?==?process)
{
freeBlock?temp?;
temp.size?=theIterator->size;
temp.startAdd=theIterator->startAdd;
FreeBlocks.push_back(temp);
theIterator=UsedBlocks.erase(theIterator);
return?true;
}else{
theIterator++;
}
}
return?false;
}
void?merger()
{
list::iterator?theIterator;
for(?theIterator?=?FreeBlocks.begin();?theIterator?!=?FreeBlocks.end();?theIterator++?)
{
list::iterator?Iterator;
for(?Iterator?=?FreeBlocks.begin();?Iterator?!=?FreeBlocks.end();?)
{
if?(theIterator->startAdd+theIterator->size==Iterator->startAdd)
{
theIterator->size=Iterator->size+theIterator->size;
Iterator=FreeBlocks.erase(Iterator);
}
else?Iterator++?;
}
}
}
void?display()
{ int?i=0;
list
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4883??2009-04-13?15:17??模擬首次適應動態分區存儲管理方案中的內存分配與回收\memorry.cpp
?????文件?????102400??2009-04-13?15:19??模擬首次適應動態分區存儲管理方案中的內存分配與回收\memorry.exe
?????文件???????4487??2009-04-13?10:11??模擬首次適應動態分區存儲管理方案中的內存分配與回收\memorry.vcproj
?????文件???????1427??2009-04-20?23:28??模擬首次適應動態分區存儲管理方案中的內存分配與回收\memorry.vcproj.E96CEF8920554E9.Administrator.user
?????文件????????950??2009-04-13?10:11??模擬首次適應動態分區存儲管理方案中的內存分配與回收\ReadMe.txt
?????文件????????212??2009-04-13?10:11??模擬首次適應動態分區存儲管理方案中的內存分配與回收\stdafx.cpp
?????文件????????276??2009-04-13?10:11??模擬首次適應動態分區存儲管理方案中的內存分配與回收\stdafx.h
?????文件?????126919??2009-04-21?11:14??模擬首次適應動態分區存儲管理方案中的內存分配與回收\模擬首次適應動態分區存儲管理方案中的內存分配與回收.pdf
?????目錄??????????0??2009-04-21?11:18??模擬首次適應動態分區存儲管理方案中的內存分配與回收
-----------?---------??----------?-----??----
???????????????241554????????????????????9
- 上一篇:用PIC16F877實現EEPROM讀寫程序
- 下一篇:(MFC) 時鐘日期程序
評論
共有 條評論