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

📄 container.cpp

📁 操作系统的几个实验
💻 CPP
字号:
// container.cpp: implementation of the container class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "实验室.h"
#include "container.h"
#include "Consumer.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

container::container()
{
	for(int i=0;i<2000;i++)m[i]='\0';
	h=t=0;
}

container::~container()
{

}

int container::HowManyMemory()
{

	if(t-h==0)return 2000;
	else if(t-h>0)return ((1999-(t-h))%2000);
	else return ((h-t-1)%2000);
}


void container::AddData(Producer p)
{
	m[t]=0xaa;
	t=(t+1)%2000;
	m[t]=p.len;
	t=(t+1)%2000;

	for(int j=0;j<(int)p.len;j++)
	{
		m[t]=p.message[j];
		t=(t+1)%2000;
	}
	m[t]=p.CheckSum;
}



void container::DeleteData(CConsumer *c)
{
	c->head=m[h];
	h=(h+1)%2000;
	c->len=m[h];
	h=(h+1)%2000;
	for(int i=0;i<c->len;i++)
	{
		c->message[i]=m[h];
		h=(h+1)%2000;
	}
	c->CheckSum=m[h];
	h=(h+1)%2000;
}

void container::ReFlash()
{
	for(int i=0;i<2000;i++)m[i]='\0';
	h=t=0;
}

⌨️ 快捷键说明

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