Standard C++ Library Class Reference
Click on the banner to return to the Class Reference home page.
©Copyright 1996 Rogue Wave Software
allocator
Summary
The default allocator object for storage management in Standard Library containers.
Contents
Synopsis●
Description●
The Alternate Allocator●
Standard Interface●
Types●
Operations●
Alternate Interface●
Alternate Allocator Description●
See Also●
Synopsis
#include <memory>
class allocator;
Description
Containers in the Standard Library allow you control of storage management through the use of allocator objects. Each
container has an allocator template parameter specifying the type of allocator to be used. Every constructor, except the copy
constructor, provides an allocator parameter, allowing you to pass in a specific allocator. A container uses that allocator for all
storage management.
The library provides a default allocator, called allocator. This allocator uses the global new and delete operators. By default, all
containers use this allocator. You can also design your own allocator, but if you do so it must provide an appropriate interface.
The standard interface and an alternate interface are specified below. The alternate interface will work on all supported
compilers.
The Alternate Allocator
As of this writing, very few compilers support the full range features needed by the standard allocator. If your compiler does
not support member templates (both classes and functions) then you must use the alternate allocator interface we provide. This
alternate interface requires no special features of a compiler and offers most of the functionality of the standard allocator
interface. The only thing missing is the ability to use special pointer and reference types. The alternate allocator fixes these as
T* and T&. If your compiler supports partial specialization then even this restriction is removed.
From outside a container, use of the alternate allocator is transparent. Simply pass the allocator as a template or function
parameter exactly as you would the standard allocator.
Within a container, the alternate allocator interface is more compilicated to use because it requires two separate classes, rather
than one class with another class nested inside. If you plan to write your own containers and need to use the alternate allocator