📄 mos_stor.cpp
字号:
// Mos_stor.cpp: implementation of the CMos_stor class.
// Write by biti_zx,April,2002.
// Copyright (c) By biti_zx 2002.
// All rights reserved.
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Mos.h"
#include "Mos_stor.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMos_stor m_stor;
CMos_stor::CMos_stor()
{
}
CMos_stor::~CMos_stor()
{
}
bool CMos_stor::mem_allocation(int m,memtype *&ret)
//返回链头指针传给returnptr
{
if(MEMFRC<m)return false;//空间不足
else{
memtype* p = NULL;
ret=MEMPTR;
for(int j=0;j<m;j++)
{
MEMPTR->used=1;//置成已使用
p = MEMPTR;
MEMPTR=MEMPTR->forwp;
}
if(m==MEMFRC) //全部分完
MEMPTR=MEMTRA=NULL;
p->forwp = NULL;//断开关联
MEMFRC-=m;
m_UI.DrawRect(30-MEMFRC,30,IDC_PIC_MEM);
return true;
}
}
void CMos_stor::mem_free(int m,memtype *ptr) //m,回收的页数
{
if(MEMFRC==0) //原链已空
{
MEMTRA=MEMPTR=ptr;//置新链头
for(int i=1;i<m;i++)
{
MEMTRA->used=0; //置为未使用
MEMTRA=MEMTRA->forwp;
}
MEMTRA->used=0;//最后一页
MEMTRA->forwp=NULL;
}
else//原链不空
{
MEMTRA->forwp=ptr;
for(int t=0;t<m;t++)
{
MEMTRA=MEMTRA->forwp;
MEMTRA->used=0; //置为未使用
}
MEMTRA->forwp=NULL;
}
MEMFRC+=m;
m_UI.DrawRect(30-MEMFRC,30,IDC_PIC_MEM);
}
bool CMos_stor::dsk_allocation(int m,maptype *&t)//分配链以t返回
{
if(DSFRC<m)return false;//不够分
else{
maptype *p = NULL;
t=DSPTR;
for(int i=0;i<m;i++)
{
DSPTR->used=1;
p = DSPTR;
DSPTR=DSPTR->forwp;
}
if(m==DSFRC)//正好分完
DSPTR=DSTRA=NULL;
p->forwp = NULL;
DSFRC=DSFRC-m;
m_UI.DrawRect(100-DSFRC,100,IDC_PIC_DSK);
return true;
}
}
void CMos_stor::dsk_free(int m,maptype *a)
{
if(DSPTR==NULL) //空链
{
DSPTR=a;
maptype *t=a; //指向a
t->used=0; //置为没用过的
for(int i=0;i<m-1;m++)
{
t->used=0;//置为没用过的
t=t->forwp; //向后移动
}
t->used=0;
DSTRA=t;
DSTRA->forwp=NULL;
}
else{
DSTRA->forwp=a;
for(int i=0;i<m;i++)
{
DSTRA=DSTRA->forwp;
DSTRA->used=0;
}
DSTRA->forwp=NULL;
}
DSFRC=DSFRC+m;
m_UI.DrawRect(100-DSFRC,100,IDC_PIC_DSK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -