| 201 | } |
| 202 | |
| 203 | static 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 | |
| 242 | static void testAllocatorMalloc() |
| 243 | { |