本文整理汇总了C++中MemChunk::Deallocate方法的典型用法代码示例。如果您正苦于以下问题:C++ MemChunk::Deallocate方法的具体用法?C++ MemChunk::Deallocate怎么用?C++ MemChunk::Deallocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemChunk
的用法示例。
在下文中一共展示了MemChunk::Deallocate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Deallocate
void FixedAllocator::Deallocate(void *p)
{
assert(last_dealloc_);
assert(!chunks_.empty());
// find the chunk that holds the pointer.
last_dealloc_ = FindChunk(p);
assert(last_dealloc_);
// found the chunk, so forwards deallocation request to it.
last_dealloc_->Deallocate(p, block_size_);
// the chunk is empty, should we free it?
if (last_dealloc_->blocks_available_ == blocks_)
{
MemChunk *last_chunk = &chunks_.back();
if (last_chunk = last_dealloc_)
{
if (chunks_.size() > 1 && last_dealloc_[-1].blocks_available_ == blocks_)
{
// there are two free chunk, so free one.
last_chunk->Free();
chunks_.pop_back();
last_alloc_ = last_dealloc_ = &chunks_.front();
}
}
else if (last_chunk->blocks_available_ == blocks_)
{
// there are two free chunk, so free one.
last_chunk->Free();
chunks_.pop_back();
last_alloc_ = last_dealloc_;
}
else
{
// move the empty chunk to the bottom.
std::swap(*last_dealloc_, *last_chunk);
last_alloc_ = last_dealloc_;
}
}
}