| 2198 | |
| 2199 | template <class Extent> |
| 2200 | void MemPool::newExtent(size_t& size, Extent** linkedList) |
| 2201 | { |
| 2202 | // No large enough block found. We need to extend the pool |
| 2203 | void* memory = NULL; |
| 2204 | const unsigned TOTAL_OVERHEAD = DoubleLinkedList::MEM_OVERHEAD + GUARD_BYTES + VALGRIND_REDZONE; |
| 2205 | const unsigned FROM_LIMIT = mediumLimits[10]; // 4224 // 10 |
| 2206 | const unsigned TO_LIMIT = mediumLimits[15]; // 7552 // 15 |
| 2207 | |
| 2208 | size_t ext_size = size + MEM_ALIGN(sizeof(Extent)); |
| 2209 | const bool allocByParent = parent && (ext_size <= TO_LIMIT); |
| 2210 | |
| 2211 | if (allocByParent) |
| 2212 | { |
| 2213 | size_t from = FROM_LIMIT; |
| 2214 | if (ext_size + TOTAL_OVERHEAD > from) |
| 2215 | from = ext_size + TOTAL_OVERHEAD; |
| 2216 | ext_size = TO_LIMIT; |
| 2217 | if (ext_size < from) |
| 2218 | ext_size = from; |
| 2219 | |
| 2220 | fb_assert(ext_size < DEFAULT_ALLOCATION); |
| 2221 | memory = parent->getExtent(from, ext_size); |
| 2222 | } |
| 2223 | else |
| 2224 | { |
| 2225 | fb_assert(ext_size <= DEFAULT_ALLOCATION); |
| 2226 | ext_size = DEFAULT_ALLOCATION; |
| 2227 | memory = allocRaw(ext_size); |
| 2228 | fb_assert(ext_size == DEFAULT_ALLOCATION); // Make sure extent size is as expected |
| 2229 | } |
| 2230 | |
| 2231 | Extent* extent = new(memory) Extent(linkedList, ext_size); |
| 2232 | size = extent->spaceRemaining; |
| 2233 | } |
| 2234 | |
| 2235 | MemoryPool* MemoryPool::createPool(MemoryPool* parentPool, MemoryStats& stats) |
| 2236 | { |