1. Improving Performance With Custom Pool Allocators for STL.
- Author
-
Aue, Anthony
- Subjects
- *
ASSIGNMENT problems (Programming) , *C++ , *COMPUTER programming , *COMPUTER algorithms , *ELECTRONIC data processing - Abstract
This paper describe a highly flexible and configurable replacement for std::allocator for use with node-based standard containers. One of the most attractive features of C++ is the Standard Template Library (STL). At the root of the STL is an incredibly rich set of containers. The STL provides default implementations for contiguous storage, lists, sets and maps. As is always the case, however, general solutions do not come without a price. The default implementations of std::allocator provided by STL implementations vary in complexity by the STL implementation from thin wrappers around new and delete to carefully built allocators running to thousands of lines of code. Pool allocators are an extremely efficient method for providing allocation services for objects of fixed size s. The basic strategy is to reserve a chunk of memory sufficient for storing N objects of size s all at once. A potentially more serious caveat is that, since the allocator uses nonstatic data, it is not technically standard compliant because the standard requires that allocators of the same type be equivalent. The StoragePolicy is the most interesting and challenging part of the allocator. It dictates how individual PoolChunks are stored in a BunchOfChunks. It is also responsible for actually releasing the memory allocated by BunchOfChunks. StoragePolicyBoundary is similar to StoragePolicySimple, but it does a bit of extra housekeeping to enforce a boundary between full and nonfull chunks. Each BunchOfChunks object has a GrowthPolicy member that is responsible for calculating the size of the next chunk to allocate.
- Published
- 2005