Topic: Allocator requirements
Author: "Kevin S. Van Horn" <ksvhsoft@xmission.com>
Date: 1997/09/04 Raw View
Does anyone know where I can find the requirements for an STL-compatible
allocator?? I'd like to know how to write one myself. I've looked in
the Dec. '96 WP, but although I found plenty of details on the
allocators provided as part of the standard library, I couldn't find
anyplace where it said what the requirements on a user-defined allocator
(to be used with an STL container) were. I also looked at the
documentation that comes with SGI STL; it provides some extra
allocators, but again, it says nothing about how to design your own. I
keep on hearing that the whole idea of allocators is to allow other
types of memory, such as shared memory or persistent objects, but I've
never seen a concrete example.
One of my major questions is this: must the pointer and reference types
of an allocator be actual pointers and references, or can they be types
that behave much like a pointer or reference? The latter would seem to
be required if you were to have an allocator that allowed persistent
objects. But then you run into an inconsistency in the requirements for
iterators: the dereference operator is required to return a reference;
it doesn't allow a type that "behaves like" a reference (and I'm not
100% sure what that would mean) to be returned.
-----------------------------------------------------------------
Kevin S. Van Horn | ksvhsoft@xmission.com
KSVH Software and Consulting | http://www.xmission.com/~ksvhsoft/
---
[ 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
]
Author: Hans-Juergen Boehm <boehm@mti.mti.sgi.com>
Date: 1997/09/05 Raw View
Kevin S. Van Horn wrote:
>
> Does anyone know where I can find the requirements for an STL-compatible
> allocator?? I'd like to know how to write one myself. I've looked in
> the Dec. '96 WP, but although I found plenty of details on the
> allocators provided as part of the standard library, I couldn't find
> anyplace where it said what the requirements on a user-defined allocator
> (to be used with an STL container) were. I also looked at the
> documentation that comes with SGI STL; it provides some extra
> allocators, but again, it says nothing about how to design your own. I
> keep on hearing that the whole idea of allocators is to allow other
> types of memory, such as shared memory or persistent objects, but I've
> never seen a concrete example.
>
There is a draft of a design document for STL allocators in
http://reality.sgi.com/boehm/alloc.html
Some variant of that will eventually make it to the SGI STL site.
Note that SGI STL allocators are not draft standard allocators, which
are not HP STL allocators. The draft standard specifies a different set
of requirements. SGI STL uses a minimalist interface (except that
reallocate is included to allow somewhat better performance in some
cases); it's easiest to write your own, but there are some uses for
which they are less convenient. The draft standard interface is
complex; it currently defines the syntax for a number of other
facilities, but largely leaves the details of the semantics of those, or
whether they are really supported, up to the implementation.
SGI STL allocators are plain classes, and do not rely crucially on
templates (though they are of course used mostly as template paramters).
Even simple uses of draft standard allocators rely crucially on member
templates. It should be easy to build an adaptor that turns an SGI STL
allocator into a draft standard allocator, but not the other way around.
--
Hans-Juergen Boehm
boehm@mti.sgi.com
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]