⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 computerosexp_04_02.cpp

📁 内存管理
💻 CPP
字号:
#include "stdafx.h"
#include "MBT.h"
#include "MBTList.h"
#include <iostream.h>
#include "PCB.h"
char *name[4] = {"AA", "BB", "CC", "DD"};
int fpPCBLen[4] = {5, 20, 10, 20};
int fpStartAdd[4] = {20, 35, 70, 110};
int fpLen[4] = {5, 20, 10, 20};
int kxStartAdd[4] = {25, 55, 80, 130};
int kxLen[4] = {10, 15, 30, 20};
void Print(MBTList *fpList, MBTList *kxList)
{
	cout << "初始数据" << endl;
	cout << "已分区" << endl;
	fpList->Print();
	cout << "未分区" << endl;
	kxList->Print();
	cout << endl << endl << endl;
}
void DestributM(MBTList *fpList, MBTList *kxList, PCB *pcb, int sort)
{
	MBT *mbt = kxList->Destribute(pcb);
	fpList->InsertMBT(mbt, sort);
	cout << "分配" << pcb->name << "后的数据" << endl;
	cout << "已分区" << endl;
	fpList->Print();
	cout << "未分区" << endl;
	kxList->Print();
}
void RecyleM(MBTList *fpList, MBTList *kxList, char *name, int sort)
{
	cout << endl << endl << endl;
	MBT *get = fpList->Recyle(name);
	kxList->UnionMBT(get, sort);
	cout << "回收" << name << "后的数据" << endl;
	cout << "已分区" << endl;
	fpList->Print();
	cout << "未分区" << endl;
	kxList->Print();
}
int main(int argc, char* argv[])
{
	int sort = 1;
	MBTList *fpList = new MBTList();
	MBTList *kxList = new MBTList();
	for(int i = 0; i < 4; i++)
	{
		PCB *pcb = new PCB(name[i], fpPCBLen[i]);

		MBT *fpMBT = new MBT(1, pcb);
		fpMBT->startAdd = fpStartAdd[i];
		fpMBT->len = fpLen[i];
		fpList->InsertMBT(fpMBT, sort);

		MBT *kxMBT = new MBT(0, 0);
		kxMBT->startAdd = kxStartAdd[i];
		kxMBT->len = kxLen[i];
		kxList->InsertMBT(kxMBT, sort);
	}
	Print(fpList, kxList);
	char *n = "EE";
	int fpL =  17;
	PCB *p = new PCB(n, fpL);
	DestributM(fpList, kxList, p, sort);
	RecyleM(fpList, kxList, "EE", sort);
	RecyleM(fpList, kxList, "CC", sort);
	delete kxList, fpList;
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -