本文整理汇总了C++中Heap::Deallocate方法的典型用法代码示例。如果您正苦于以下问题:C++ Heap::Deallocate方法的具体用法?C++ Heap::Deallocate怎么用?C++ Heap::Deallocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap::Deallocate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST( HeapFixtureTest, Heap_AllocDeallocTest ) {
static const Uint32 amt = 1024;
Heap<HeapTest,amt> heapTest;
HeapTest* arr[amt];
for( cbl::Uint32 i = 0; i < amt; ++i ) {
arr[i] = heapTest.Allocate();
ASSERT_TRUE( arr[i] != NULL );
arr[i]->x = i + 5;
arr[i]->y = i + 5;
arr[i]->z = i + 5;
}
ASSERT_TRUE( heapTest.Allocate() == NULL );
for( cbl::Uint32 i = 0; i < amt; ++i ) {
ASSERT_EQ( arr[i]->x, i + 5 );
ASSERT_EQ( arr[i]->y, i + 5 );
ASSERT_EQ( arr[i]->z, i + 5 );
}
ASSERT_TRUE( heapTest.Allocate() == NULL );
for( cbl::Uint32 i = 0; i < amt; ++i ) {
ASSERT_TRUE( heapTest.Deallocate( arr[i] ) );
}
for( cbl::Uint32 i = 0; i < amt; ++i ) {
ASSERT_FALSE( heapTest.Deallocate( arr[i] ) );
}
// Test the allocations for a second time.
for( cbl::Uint32 i = 0; i < amt; ++i ) {
arr[i] = heapTest.Allocate();
arr[i]->x = i + 5;
arr[i]->y = i + 5;
arr[i]->z = i + 5;
}
ASSERT_TRUE( heapTest.Allocate() == NULL );
for( cbl::Uint32 i = 0; i < amt; ++i ) {
ASSERT_EQ( arr[i]->x, i + 5 );
ASSERT_EQ( arr[i]->y, i + 5 );
ASSERT_EQ( arr[i]->z, i + 5 );
}
ASSERT_TRUE( heapTest.Allocate() == NULL );
for( cbl::Uint32 i = 0; i < amt; ++i ) {
ASSERT_TRUE( heapTest.Deallocate( arr[i] ) );
}
for( cbl::Uint32 i = 0; i < amt; ++i ) {
ASSERT_FALSE( heapTest.Deallocate( arr[i] ) );
}
}