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

Function testAllocatorMemoryPool

src/common/classes/misc/class_perf.cpp:203–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203static void testAllocatorMemoryPool()
204{
205 printf("Test run for Firebird::MemoryPool...\n");
206 start();
207 Firebird::MemoryPool* pool = Firebird::MemoryPool::createPool();
208 MallocAllocator allocator;
209 BePlusTree<AllocItem, AllocItem, MallocAllocator, DefaultKeyValue<AllocItem>, AllocItem> items(&allocator),
210 bigItems(&allocator);
211 // Allocate small items
212 int i, n = 0;
213 for (i = 0; i < ALLOC_ITEMS; i++) {
214 n = n * 47163 - 57412;
215 AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE) / 2 + 1)};
216 items.add(temp);
217 }
218 // Deallocate half of small items
219 n = 0;
220 if (items.getFirst()) do {
221 pool->deallocate(items.current().item);
222 n++;
223 } while (n < ALLOC_ITEMS / 2 && items.getNext());
224 // Allocate big items
225 for (i = 0; i < BIG_ITEMS; i++) {
226 n = n * 47163 - 57412;
227 AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE) / 2 + 1)};
228 bigItems.add(temp);
229 }
230 // Deallocate the rest of small items
231 while (items.getNext()) {
232 pool->deallocate(items.current().item);
233 }
234 // Deallocate big items
235 if (bigItems.getFirst()) do {
236 pool->deallocate(bigItems.current().item);
237 } while (bigItems.getNext());
238 Firebird::MemoryPool::deletePool(pool);
239 report();
240}
241
242static void testAllocatorMalloc()
243{

Callers 1

mainFunction · 0.85

Calls 8

startFunction · 0.70
reportFunction · 0.70
allocateMethod · 0.45
addMethod · 0.45
getFirstMethod · 0.45
deallocateMethod · 0.45
currentMethod · 0.45
getNextMethod · 0.45

Tested by

no test coverage detected