本文整理汇总了C++中Allocator::GetBlockSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Allocator::GetBlockSize方法的具体用法?C++ Allocator::GetBlockSize怎么用?C++ Allocator::GetBlockSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Allocator
的用法示例。
在下文中一共展示了Allocator::GetBlockSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xmalloc
/// Reallocates a memory block previously allocated with xalloc.
/// @param[in] ptr - a pointer to a block created with xalloc.
/// @param[in] size - the client requested block size to create.
extern "C" void *xrealloc(void *oldMem, size_t size)
{
if (oldMem == 0)
return xmalloc(size);
if (size == 0)
{
xfree(oldMem);
return 0;
}
else
{
// Create a new memory block
void* newMem = xmalloc(size);
if (newMem != 0)
{
// Get the original allocator instance from the old memory block
Allocator* oldAllocator = get_block_allocator(oldMem);
size_t oldSize = oldAllocator->GetBlockSize() - sizeof(Allocator*);
// Copy the bytes from the old memory block into the new (as much as will fit)
memcpy(newMem, oldMem, (oldSize < size) ? oldSize : size);
// Free the old memory block
xfree(oldMem);
// Return the client pointer to the new memory block
return newMem;
}
return 0;
}
}