O'Reilly logo

The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 15. Allocators

Allocators were introduced in Section 3.4. They represent a special memory model and are an abstraction used to translate the need to use memory into a raw call for memory. This chapter describes allocators in detail.

Using Allocators as an Application Programmer

For the application programmer, using different allocators should be no problem. You simply have to pass the allocator as a template argument. For example, the following statements create different containers and strings using the special allocator MyAlloc<>:

// a vector with special allocator
   std::vector<int,MyAlloc<int> > v;


   // an int/float map with special allocator
   std::map<int,float,less<int>, 
            MyAlloc<std::pair<const int,float> > > m;



   // a string with special ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required