Allocators |
To accommodate varying mechanisms
for memory allocation, the Standard Template Library (STL) does not explicitly
use the standard new
and delete operators
anywhere in the library. Instead, all STL containers use special objects called
allocators to allocate and deallocate storage.
In the ANSI standard, the type of allocator is specified as a template argument when the container is instantiated. The template argument defaults to a heap-based allocator. Unfortunately, few compilers currently implement default template parameters, so Standards<ToolKit> takes the following approach.
OS_NO_ALLOCATORS is defined, then
every container uses the default standard allocator allocator
to manage storage. The template argument that normally specifies the allocator
is removed from the interface, thus simplifying the declaration of STL
containers.
vector<
int > x ; // Declaration
using OS_NO_ALLOCATORS.
Most developers prefer to use Standards<ToolKit> in the above configuration, due to its familiar style. Using this approach does not inhibit code portability, however, since all C++ compilers will eventually support default template arguments. This is simply another approach for working around the deficiencies in current compiler technology.
OS_NO_ALLOCATORS is not defined, the
allocator must be specified in the template argument everywhere the container is
specified.
vector<
int, allocator< int > > x ;
// Normal declaration
If your compiler does not support default template arguments (and most compilers do not), this can be become quite a task. Consequently, few developers use the above configuration.
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.