计算机等级考试内存池的C++实现代码(2)
时间:
未知2
资讯
pmb_block=pmb_block->m_pNext;
if(!pmb_block)
return;
}
pmb_block->m_nFree++;//可分配数目+1
*((USHORT*)pfree)=pmb_block->m_nFirst;
pmb_block->m_nFirst=(USHORT)((ULONG)pfree-(ULONG)pmb_block->m_data)/m_nUnitSize;
if(pmb_block->m_nFree*m_nUnitSize==pmb_block->m_nSize)//如何该链块为空
{
pmb_preblock->m_pNext=pmb_block->m_pNext;
if((ULONG)pmb_preblock==(ULONG)m_pFirst)
m_pFirst=NULL;
delete pmb_block;
}
}
MemoryPool::~MemoryPool(void)
{
if(m_pFirst)
FreeMemoryBlock(m_pFirst);
}
void MemoryPool::FreeMemoryBlock(MemoryBlock *pblock)
{
if(pblock->m_pNext)
FreeMemoryBlock(pblock->m_pNext);
delete pblock;
pblock=NULL;
}