文档介绍:空闲磁盘存储的管理:位示图法
1:建立相应的数据结构
2:磁盘上建立一个文件,文件长度设为10MB,为该文件来模拟一个磁盘,磁盘的物理块大小为512字节
3:显示每次磁盘的请求和空间释放后的位示图状态
4显示每次磁盘的请求和空间释放后的全磁盘的状态
5:模拟文件的创建和删除,从而产生磁盘潘快请求和释放,验证以上设计
代码:
// OS暑?期ú课?程ì设Θ?计?.cpp : 定¨义?控?制?台?应畖用?程ì序ò的?入?口ú点?。£
//
#include ""
#include <iostream>
#include <string>
#include <>
using namespace std ;
//文?件t类え?
class file
{
public:
string name ;
int occupy ;
int grade_block ;
int start ;
};
#define MAX_LINE 3
#define MAX_COLUMN 32
int BIT[32][1000];
int byte[MAX_LINE] ;
int file_count;
int judge[32] ;
int judge2[32];
int cycle ;
file f[1000];
void init(int line ,int column);
void show() ;
void set(int now_location, int occupy );
void clear(int now_location, int occupy);
void bitset(int index ,int temp_block_quantity);
void create_file(string temp_name, int upy );
void delete_file(string name);
bool byte_judge(int num,int i);
int _tmain(int argc, _TCHAR* argv[])
{
string cmd;
string file_name ;
int upy ;
init( MAX_LINE, MAX_COLUMN ) ; //初?始?化ˉ
while ( cin >> cmd ) //
{
if( "q" == cmd || "Q" == cmd )
{
exit(0) ;
return 0 ;
}
cin >> file_name ;
if("create" == cmd)
{
cin >>upy ;
create_file(file_name,upy);
}
else
{
delete_file(file_name) ;
}
}
return 0;
}
void show()
{
for(int i = 0 ; i < MAX_LINE ; i ++)
{
for(int j = 0 ; j < MAX_COLUMN ; j ++)
{
//cout<<BI