Building your own allocators, Using the standard allocator interface – HP Integrity NonStop H-Series User Manual
Page 199
![background image](/manuals/396950/199/background.png)
Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
Building Your Own Allocators
Defining your own allocator is a relatively simple process. The Standard C++ Library describes a
particular interface, consisting of types and functions. An allocator that conforms to the Standard
must match the syntactic requirements for these member functions and types. The Standard C++
Library also specifies a portion of the semantics for the allocator type.
The Standard C++ Library allocator interface relies heavily on member templates. As of this
writing, many compilers do not yet support both member function templates and member class
templates. This makes it impossible to implement a standard allocator. Rogue Wave's
implementation of the Standard C++ Library provides an alternative allocator interface that
provides most of the power of the standard interface, without requiring unavailable compiler
features. This interface differs significantly from the standard interface, and will not work with
other vendors' versions of the Standard C++ Library.
We recommend that when you define an allocator and implement containers, you provide both
the standard interface and the Rogue Wave interface. This will allow you to use allocators now,
and to take advantage of the standard once it becomes available on your compiler.
The remainder of this section describes the requirements for the Standard C++ Library allocator,
the requirements for Rogue Wave's alternative allocator, and some techniques that specify how
to support both interfaces in the same code base.
Using the Standard Allocator Interface
An allocator that conforms to the Standard C++ Library allocator specification must have the
following interface. The example uses my_allocator as a place holder for your own allocator
name:
class my_allocator
{
typedef implementation_defined size_type;
typedef implementation_defined difference_type
template
struct types {
typedef implementation_defined pointer;
typedef implementation_defined const_pointer;
typedef implementation_defined reference;
typedef implementation_defined const_reference;