MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / testAllocator

Function testAllocator

src/common/classes/misc/class_test.cpp:527–627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525};
526
527void testAllocator()
528{
529 printf("Test Firebird::MemoryPool\n");
530 MemoryPool* parent = getDefaultMemoryPool();
531 MemoryPool* pool = MemoryPool::createPool(parent);
532
533 MallocAllocator allocator;
534 BePlusTree<AllocItem, AllocItem, MallocAllocator, DefaultKeyValue<AllocItem>, AllocItem> items(&allocator),
535 bigItems(&allocator);
536
537 Vector<void*, LARGE_ITEMS> la;
538 printf("Allocate %d large items: ", LARGE_ITEMS);
539 int i;
540 for (i = 0; i<LARGE_ITEMS; i++) {
541 la.add(pool->allocate(LARGE_ITEM_SIZE ALLOC_ARGS));
542 VERIFY_POOL(pool);
543 }
544 VERIFY_POOL(pool);
545 printf(" DONE\n");
546
547 printf("Allocate %d items: ", ALLOC_ITEMS);
548 int n = 0;
549 VERIFY_POOL(pool);
550 for (i = 0; i < ALLOC_ITEMS; i++) {
551 n = n * 47163 - 57412;
552 // n = n * 45578 - 17651;
553 AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE) / 2 + 1 ALLOC_ARGS)};
554 items.add(temp);
555 }
556 printf(" DONE\n");
557 VERIFY_POOL(pool);
558 VERIFY_POOL(parent);
559
560 printf("Deallocate half of items in quasi-random order: ");
561 n = 0;
562 if (items.getFirst()) do {
563 pool->deallocate(items.current().item);
564 n++;
565 } while (n < ALLOC_ITEMS / 2 && items.getNext());
566 printf(" DONE\n");
567 VERIFY_POOL(pool);
568 VERIFY_POOL(parent);
569
570 printf("Allocate %d big items: ", BIG_ITEMS);
571 n = 0;
572 VERIFY_POOL(pool);
573 for (i = 0; i < BIG_ITEMS; i++) {
574 n = n * 47163 - 57412;
575 // n = n * 45578 - 17651;
576 AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE) / 2 + 1 ALLOC_ARGS)};
577 bigItems.add(temp);
578 }
579 printf(" DONE\n");
580 VERIFY_POOL(pool);
581 VERIFY_POOL(parent);
582
583 printf("Allocate max recommended medium buffer (%d bytes): ", MemoryPool::MAX_MEDIUM_BLOCK_SIZE);
584 void* maxMedium = pool->allocate(MemoryPool::MAX_MEDIUM_BLOCK_SIZE ALLOC_ARGS);

Callers 1

mainFunction · 0.85

Calls 8

getDefaultMemoryPoolFunction · 0.85
addMethod · 0.45
allocateMethod · 0.45
getFirstMethod · 0.45
deallocateMethod · 0.45
currentMethod · 0.45
getNextMethod · 0.45
print_contentsMethod · 0.45

Tested by

no test coverage detected