beautypg.com

Creating your own containers, Meeting the container requirements, Meeting the allocator interface requirements – HP Integrity NonStop H-Series User Manual

Page 212

background image

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Creating Your Own Containers

All of the options that build on existing Standard C++ Library containers incur a certain amount
of overhead. When performance demands are critical, or the container requirements very specific,
there may be no choice but to implement a container from scratch.

When building from scratch, there are three sets of design requirements that you must meet:

Container interface requirements;

Allocator interface requirements;

Iterator requirements.

We'll talk about each of these below.

Meeting the Container Requirements

The Standard C++ Library defines general interface requirements for containers, and specific
requirements for specialized containers. When you create a container, the first part of your task is
making sure that the basic interface requirements for a container are met. In addition, if your
container will be a sequence or an associative container, you need to provide all additional pieces
specified for those categories. For anything but the simplest container, this is definitely not a task
for the faint of heart.

It's very important to meet the requirements so that users of the container will know exactly what
capabilities to expect without having to read the code directly. Review the sections on individual
containers for information about the container requirements.

Meeting the Allocator Interface Requirements

A user-defined container will make use of the allocator interface for all storage management. (An
exception to this is a container that will exist in a completely self-contained environment where
there will be no need for substitute allocators.)

The basic interface of an allocator class consists of a set of typedefs, a pair of allocation
functions, allocate and deallocate, and a pair of construction/destruction members, construct and
destroy. The typedefs are used by a container to determine what pointers, references, sizes and
differences look like. (A difference is a distance between two pointers.) The functions are used to

This manual is related to the following products: