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

📄 pagemetathesisdlg.cpp

📁 用VC++6.0模拟实现最佳置换算法、最近最久未使用算法、先进先出置换算法。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					{
						itoa(phi[z],CSnum,10);
						memo+=CSnum;
						memo+="       ";
					}
				}
				m_display.InsertString(m_display.GetCount(),memo);
			}
		}
		if(metathesis)	//有中断
		{
			if(space)	//有空页面,插入页面中断
			{
				int m;
				for(z=0;z<phisical_size;z++)
				{
					if(priority[z]==0)
					{
						priority[z]=phisical_size;
						phi[z]=addr[i];
						m=z;
						z=phisical_size;
					}
					else 
						priority[z]-=1;
				}
				if(priority[phisical_size-1]!=0) space=false;	//最后一个页面不空,则无空页面
				memo=" ";
				for(z=0;z<phisical_size;z++)
				{
					itoa(phi[z],CSnum,10);
					if(m<z) memo+=" ";
					else memo+=CSnum;
					memo+="       ";
				}
				memo+="  √        插入页面";
				num_fail++;
				m_display.InsertString(m_display.GetCount(),memo);
			}
			else	//无空页面,替换页面中断
			{
				for(z=0;z<phisical_size;z++)
				{
					if(priority[z]==1)
					{
						priority[z]=phisical_size;
						phi[z]=addr[i];
					}
					else
						priority[z]-=1;
				}
				memo=" ";
				for(z=0;z<phisical_size;z++)
				{
					itoa(phi[z],CSnum,10);
					memo+=CSnum;
					memo+="       ";
				}
				memo+="  √        替换页面";
				num_fail++;
				m_display.InsertString(m_display.GetCount(),memo);
			}
		}
	}
	CString output="FIFO算法  总页面数:";
	char temporary[4];
	itoa(point_array,temporary,10);
	output+=temporary;
	itoa(num_fail,temporary,10);
	output+="  缺页中断次数:";
	output+=temporary;
	output+="  缺页率为:";
	num_fail=num_fail*100/point_array;
	itoa(num_fail,temporary,10);
	output+=temporary;
	output+="%";
	m_display.InsertString(0,output);
	output="";
	m_display.InsertString(1,output);
}
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPageMetathesisDlg dialog

CPageMetathesisDlg::CPageMetathesisDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPageMetathesisDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPageMetathesisDlg)
	m_sernum = _T("");
	m_phinum = 0;
	m_hint = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPageMetathesisDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageMetathesisDlg)
	DDX_Control(pDX, IDC_EDIT_SERNUM, m_sernum_control);
	DDX_Control(pDX, IDC_EDIT_PHINUM, m_phinum_control);
	DDX_Control(pDX, IDC_LIST_DISPLAY, m_display);
	DDX_Text(pDX, IDC_EDIT_SERNUM, m_sernum);
	DDX_Text(pDX, IDC_EDIT_PHINUM, m_phinum);
	DDV_MinMaxInt(pDX, m_phinum, 1, 9);
	DDX_Text(pDX, IDC_EDIT_HINT, m_hint);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPageMetathesisDlg, CDialog)
	//{{AFX_MSG_MAP(CPageMetathesisDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_CLR, OnButtonClr)
	ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
	ON_BN_CLICKED(IDC_BUTTON_LRU, OnButtonLru)
	ON_BN_CLICKED(IDC_BUTTON_FIFO, OnButtonFifo)
	ON_BN_CLICKED(IDC_BUTTON_ABOUT, OnButtonAbout)
	ON_BN_CLICKED(IDC_BUTTON_Optimal, OnBUTTONOptimal)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPageMetathesisDlg message handlers

BOOL CPageMetathesisDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_phinum=1;
	m_sernum="7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,1,7,0,1";
	UpdateData(FALSE);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPageMetathesisDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CPageMetathesisDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPageMetathesisDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPageMetathesisDlg::OnButtonClr() 
{
	// TODO: Add your control notification handler code here
	m_phinum=1;
	m_hint="";
	m_sernum="";
	UpdateData(FALSE);
	m_display.ResetContent();
	m_sernum_control.SetFocus();
}

void CPageMetathesisDlg::OnButtonExit() 
{
	// TODO: Add your control notification handler code here
	OnOK();
}

void CPageMetathesisDlg::OnBUTTONOptimal() 
{
	// TODO: Add your control notification handler code here
	if(apart())
	{
		m_hint="\r\n   最佳置换算法\r\n    (Optimal)\r\n\r\n所选择的被淘汰页面是\r\n未来最长时间不被访问\r\n的,是一种理想的置换\r\n方法。Optimal算法依\r\n据以后各页的使用情\r\n况。";
		m_sernum=sernum;
		UpdateData(FALSE);
		m_display.ResetContent();
		Optimal(num_array,m_phinum);
	}
	else 
		m_display.ResetContent();
}

void CPageMetathesisDlg::OnButtonLru() 
{
	// TODO: Add your control notification handler code here
	if(apart())
	{
		m_hint="\r\n 最近最久未使用算法\r\nLeast Recently Used\r\n\r\n所选择的被淘汰页面是\r\n未来最长时间不被访问\r\n的,LRU算法依据以前\r\n各页的使用情况。";
		m_sernum=sernum;
		UpdateData(FALSE);
		m_display.ResetContent();
		LRU(num_array,m_phinum);
	}
	else 
		m_display.ResetContent();
}

void CPageMetathesisDlg::OnButtonFifo() 
{
	// TODO: Add your control notification handler code here
	if(apart())
	{
		m_hint="\r\n  先进先出置换算法\r\n(First In First Out)\r\n\r\n总是淘汰最先进入内存\r\n的页面,该算法实现简\r\n单,效率也较低。";
		m_sernum=sernum;
		UpdateData(FALSE);
		m_display.ResetContent();
		FIFO(num_array,m_phinum);
	}
	else 
		m_display.ResetContent();
}

void CPageMetathesisDlg::OnButtonAbout() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg adlg;
	adlg.DoModal();
}

⌨️ 快捷键说明

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