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

📄 mempool.cpp

📁 这是一个可以检索大量数据的程序
💻 CPP
字号:
// MemPool.cpp: implementation of the MemPool class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "EggCilcle.h"
#include "MemPool.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
MemPool::MemPool()
{
	theblock=0;
}
bool MemPool::create(int the_size)
{
	if(theblock==0)
	{
		space=NUM;
		size=the_size;
		int i,j=NUM;
		theblock=(char*)(new char[size*j]);
		if(theblock==0)return false;
		thehead=theblock;
		for(i=0;i<j;i++)
		{
			*(char**)(theblock+i*size)=(theblock+i*size+size);
		}
		*(char**)(theblock+j*size-j)=(char*)0;
	}
	return true;
}
MemPool::~MemPool()
{
}
void*MemPool::memalloc()
{
	char* pt=thehead;
	if(thehead)
	{
		thehead=*(char**)(thehead);
		space--;
	}
	return pt;
}
void MemPool::memfree(void*p)
{
	*(char**)(p)=thehead;
	thehead=(char*)p;
	space++;
}
void MemPool::destory()
{
	if(theblock)
	{
		delete[]theblock;
		theblock=0;
		thehead=0;
		size=0;
	}
}

⌨️ 快捷键说明

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