Topic: allocators
Author: FAU <Frank.Uepping@t-online.de>
Date: Mon, 1 Jul 2002 22:10:35 GMT Raw View
I have some questions about allocators as used by the standard containers.
The standard says: "All instances of a given allocator type are required
to be interchangeable and always compare equal to each other."
Does this mean that memory allocated by one instance may be deallocated
by any instance of equal type?
E.g.:
{
class C;
allocator<C> a1, a2;
allocator<C>::pointer p = a1.allocate(1);
a1.construct(p, C());
a2.destroy(p);
a2.deallocate(p, 1);
}
Is an allocator responsible for destroying the elements that have been
constructed but not yet destroyed when it is itself destroyed?
E.g.:
{
class C;
allocator<C>::pointer p;
{
allocator<C> a;
p = a.allocate(1);
a.construct(p, C());
}
// Are the pointer p and the object pointed to by p still valid?
// If true, then these op's also should be valid.
allocator<C> a;
a.destroy(p);
a.deallocate(p, 1);
}
Why is the copy constructor a template?
"template<class U> allocator(const allocator<U>&) throw();"
However, I suspect that copy initialization is only valid if the equal operator
returns true, isn't it?
E.g.:
{
class C;
class D;
allocator<C> ac;
if (ac == allocator<D>()) {
allocator<D> ad(ac);
}
}
What gets copied in a copy constructor?
Perhaps this is bad question and I should ask instead:
What gets NOT copied in a copy constructor?
Regards
FAU
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]