Topic: [++] Placement syntax and STL


Author: Colin Rafferty <craffert@ml.com>
Date: 1997/12/18
Raw View
Reed Mangino writes:

> I have run into a situation where I need to specify the location of memory
> utilization when using an STL list<>.

> ...

> I have been looking at how to implement this mechanism when using
> an STL list<>.  Do I have to define my own allocator and pass that
> into the constructor of the list<>:

> list < foo, MyAllocator() > SpecialList;

Yes.  That is exactly what the Allocator template is for.  It was
designed to allow the user (you) to implement your own memory management
in a general way, and apply it to all the different species of
collections.

See Stroustrup's Third Edition for a very good description of using the
STL.

> Or do I somehow derive a special class of list<> itself??

No.  In fact, there are two very good reasons for not deriving from
`list':

1. The Allocator template argument is built to do exactly what you want
   (as described above).

2. You should rarely derive from a class that has no virtual functions.

--
This posting adheres to the SELF-DISCIPLINE guidelines for better
USENET discussions. See http://www.eiffel.com/discipline.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]