当前位置: 首页>>代码示例>>C++>>正文


C++ MemoryPool::print_contents方法代码示例

本文整理汇总了C++中MemoryPool::print_contents方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryPool::print_contents方法的具体用法?C++ MemoryPool::print_contents怎么用?C++ MemoryPool::print_contents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemoryPool的用法示例。


在下文中一共展示了MemoryPool::print_contents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testAllocator

void testAllocator()
{
	printf("Test Firebird::MemoryPool\n");
	MemoryPool* parent = getDefaultMemoryPool();
	MemoryPool* pool = MemoryPool::createPool(parent);

	MallocAllocator allocator;
	BePlusTree<AllocItem, AllocItem, MallocAllocator, DefaultKeyValue<AllocItem>, AllocItem> items(&allocator),
		bigItems(&allocator);

	Vector<void*, LARGE_ITEMS> la;
	printf("Allocate %d large items: ", LARGE_ITEMS);
	int i;
	for (i = 0; i<LARGE_ITEMS; i++) {
		la.add(pool->allocate(LARGE_ITEM_SIZE));
		VERIFY_POOL(pool);
	}
	VERIFY_POOL(pool);
	printf(" DONE\n");

	printf("Allocate %d items: ", ALLOC_ITEMS);
	int n = 0;
	VERIFY_POOL(pool);
	for (i = 0; i < ALLOC_ITEMS; i++) {
		n = n * 47163 - 57412;
		// n = n * 45578 - 17651;
		AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE) / 2 + 1)};
		items.add(temp);
	}
	printf(" DONE\n");
	VERIFY_POOL(pool);
	VERIFY_POOL(parent);

	printf("Deallocate half of items in quasi-random order: ");
	n = 0;
	if (items.getFirst()) do {
		pool->deallocate(items.current().item);
		n++;
	} while (n < ALLOC_ITEMS / 2 && items.getNext());
	printf(" DONE\n");
	VERIFY_POOL(pool);
	VERIFY_POOL(parent);

	printf("Allocate %d big items: ", BIG_ITEMS);
	n = 0;
	VERIFY_POOL(pool);
	for (i = 0; i < BIG_ITEMS; i++) {
		n = n * 47163 - 57412;
		// n = n * 45578 - 17651;
		AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE) / 2 + 1)};
		bigItems.add(temp);
	}
	printf(" DONE\n");
	VERIFY_POOL(pool);
	VERIFY_POOL(parent);

	printf("Deallocate the rest of small items in quasi-random order: ");
	while (items.getNext()) {
		pool->deallocate(items.current().item);
	}
	printf(" DONE\n");
	VERIFY_POOL(pool);
	VERIFY_POOL(parent);

	printf("Deallocate big items in quasi-random order: ");
	if (bigItems.getFirst()) do {
		pool->deallocate(bigItems.current().item);
	} while (bigItems.getNext());
	printf(" DONE\n");

	printf("Deallocate %d large items: ", LARGE_ITEMS/2);
	for (i = 0; i<LARGE_ITEMS/2; i++)
		pool->deallocate(la[i]);
	VERIFY_POOL(pool);
	printf(" DONE\n");


//	pool->verify_pool();
//	parent->verify_pool();
	pool->print_contents(stdout, false);
	parent->print_contents(stdout, false);
	MemoryPool::deletePool(pool);
//	parent->verify_pool();
//  TODO:
//	Test critically low memory conditions
//  Test that tree correctly recovers in low-memory conditions
}
开发者ID:andrewleech,项目名称:firebird,代码行数:87,代码来源:class_test.cpp


注:本文中的MemoryPool::print_contents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。