www.pudn.com > Mos.rar > Mos_stor.cpp


// Mos_stor.cpp: implementation of the CMos_stor class. 
// Author:Wu Yong.Released:March,2002. 
// Rewrite by Wang Hao,April,2002. 
// Copyright (c) By Wu Yong 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(MEMFRCused=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;iused=0;   //置为未使用 
			MEMTRA=MEMTRA->forwp; 
		} 
	    MEMTRA->used=0;//最后一页 
	    MEMTRA->forwp=NULL; 
	} 
	else//原链不空 
	{ 
		MEMTRA->forwp=ptr; 
		for(int t=0;tforwp; 
			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(DSFRCused=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;iused=0;//置为没用过的 
			t=t->forwp; //向后移动 
		} 
		t->used=0; 
		DSTRA=t; 
		DSTRA->forwp=NULL; 
	} 
	else{ 
			DSTRA->forwp=a; 
			for(int i=0;iforwp; 
				DSTRA->used=0; 
			} 
			DSTRA->forwp=NULL; 
	} 
	DSFRC=DSFRC+m; 
	m_UI.DrawRect(100-DSFRC,100,IDC_PIC_DSK); 
}