📄 pagemgr.cc
字号:
#include "pagemgr.h"//------------------// Page Pool Manager//------------------int blocklength; // size of a page blockint cachesize; // max. number of page blockschar **cache; // cache contvector<bool> isUsed; // bitmap for used pagesint AvailBlockNum; // # of avail blocksint getNumBlockAvail() { return AvailBlockNum;}void InitPagePool(int csize,int blksize) { //assert(csize>0); assert(blksize>0); cachesize=csize; blocklength=blksize; AvailBlockNum=csize; cache = new char*[cachesize]; for (int i=0;i<cachesize;i++) cache[i] = new char[blocklength]; isUsed.assign(cachesize,false);}void DestroyPagePool() { for (int i=0;i<cachesize;i++) delete[] cache[i]; delete[] cache;}char* GetNewBlock(int& BlockId) { BlockId=-1; for (int i=0;i<cachesize;i++) if (!isUsed[i]) { BlockId=i; isUsed[BlockId]=true; AvailBlockNum--; return cache[BlockId]; } return NULL;}void FreeBlock(int BlockId) { if (isUsed[BlockId]) { isUsed[BlockId]=false; AvailBlockNum++; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -