File ObjectPool.h
↰ Parent directory (ADS/memory)
A pool of objects of one type, beyond the book: make() builds an object in a slot of the pool and free() destroys it and keeps its slot, which the next make() takes again (the last one freed first), so that the nodes of a linked structure cost no call to the allocator, the slot just freed is still in the cache when it is used again, and the objects made one after another are next to each other in memory.
Definition (ADS/memory/ObjectPool.h)
Detailed Description
The slots come in blocks taken from the allocator A, the first of one slot and each next one twice the last up to n slots, so that a small structure takes no more than it holds; a block begins with a header that links it to the one before, so that the pool is six words and allocates nothing but its blocks, which go back to A only with the pool: a structure that shrinks keeps the memory of its largest size. The default allocator gives the blocks of 2 MB or more on huge pages [see File HugePageAllocator.h], which the nodes of a large linked structure, reached in no useful order, need not to miss the TLB at each step. Unlike Arena [see File Arena.h], an object can be freed by itself, and the pool does not destroy the objects left in it, which their owner destroys (or does not, if their destructor is trivial) before the pool dies.
allocate() and deallocate() give and take back the raw slots, the objects built and destroyed by the caller, as with std::allocator.
The contracts [see File Contract.h]: a block holds at least one slot, free() and deallocate() need an object (a slot) of the pool; the invariant is that size() objects are alive. The operations are defined in ObjectPool.tpp.
Knuth, The Art of Computer Programming, vol. 1, 3rd ed., Addison-Wesley, 1997, section 2.2.3 (the list AVAIL)
- Donato Meoli
Dipartimento di Informatica Universita’ di Pisa
by Donato Meoli
Includes
ADS/Contract.h(File Contract.h)ADS/memory/HugePageAllocator.h(File HugePageAllocator.h)ADS/memory/impl/ObjectPool.tppcstddefmemory(File Allocators.h)newtype_traitsutility