本文整理汇总了C++中Allocator::Realloc方法的典型用法代码示例。如果您正苦于以下问题:C++ Allocator::Realloc方法的具体用法?C++ Allocator::Realloc怎么用?C++ Allocator::Realloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Allocator
的用法示例。
在下文中一共展示了Allocator::Realloc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestAllocator
void TestAllocator(Allocator& a) {
EXPECT_TRUE(a.Malloc(0) == 0);
uint8_t* p = (uint8_t*)a.Malloc(100);
EXPECT_TRUE(p != 0);
for (size_t i = 0; i < 100; i++)
p[i] = (uint8_t)i;
// Expand
uint8_t* q = (uint8_t*)a.Realloc(p, 100, 200);
EXPECT_TRUE(q != 0);
for (size_t i = 0; i < 100; i++)
EXPECT_EQ(i, q[i]);
for (size_t i = 100; i < 200; i++)
q[i] = (uint8_t)i;
// Shrink
uint8_t *r = (uint8_t*)a.Realloc(q, 200, 150);
EXPECT_TRUE(r != 0);
for (size_t i = 0; i < 150; i++)
EXPECT_EQ(i, r[i]);
Allocator::Free(r);
// Realloc to zero size
EXPECT_TRUE(a.Realloc(a.Malloc(1), 1, 0) == 0);
}
示例2: grow_reallocate
/* "slow" portion of 'grow()' */
void grow_reallocate() {
int a = 64;
while( a < l )
a = a * 2;
data = (char *) al.Realloc(data, a);
assert(data);
if ( data == NULL )
size = a;
}