本文整理汇总了C++中MemoryBlock::FreeBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBlock::FreeBlock方法的具体用法?C++ MemoryBlock::FreeBlock怎么用?C++ MemoryBlock::FreeBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBlock
的用法示例。
在下文中一共展示了MemoryBlock::FreeBlock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FreeMemory
void MemoryBlockAllocator::FreeMemory(void* pAddress)
{
if (!pAddress)
{
MessagedAssert(pAddress != NULL, "You cannot free empty memory.");
TDEBUG_PRINT_FL("Hey, don't free the empty address.\n", Debugger::VerbosityDebugger::LEVEL1);
return;
}
if (!this->Contains(pAddress))
{
MessagedAssert(this->Contains(pAddress), "The address is not contained by this allocator.");
TDEBUG_PRINT_FL("Hey, this memory is not owned by me.\n", Debugger::VerbosityDebugger::LEVEL1);
return;
}
//get the memory block which contains the pAddress.
size_t memoryOffset = (size_t)pAddress - (size_t)this->_pMemoryAddress;
size_t startBit = memoryOffset / this->_blockSize;// index of the memory block
size_t align_offset = align_get_boundry_offset(sizeof(MemoryBlock), _alignment);
MemoryBlock* pBlock = reinterpret_cast<MemoryBlock*>(reinterpret_cast<char*>(_pBlocks) + startBit * align_offset);
//read how much of blocks we alloced
size_t numOfSequence = pBlock->GetNumOfAllocBlocks();
if (numOfSequence != UINT_MAX)
{
//clear the bitfield
this->_pBitfield->EraseBits(startBit, numOfSequence);
//free the memory blocks, just set memory 0
for (unsigned int i = 0; i < numOfSequence; i++)
{
pBlock->FreeBlock();
pBlock = align_get_next<MemoryBlock>(pBlock, _alignment);
}
TDEBUG_PRINT_FL("%d bytes = %d blocks of memory has been freed\n", Debugger::VerbosityDebugger::LEVEL1, numOfSequence*_blockSize, numOfSequence);
}
else
{
MessagedAssert(numOfSequence != UINT_MAX, "Memory free failed!");
TDEBUG_PRINT_FL("Free failed!\n", Debugger::VerbosityDebugger::LEVEL1);
}
}