Boost logo

Boost Users :

From: Mark A. Gibbs (gibbsmark_at_[hidden])
Date: 2003-11-17 20:42:16

Peter Dimov wrote:

>>copy of the standard). For instance, I'm not 100% sure whether or not
>>I have to call construct() after allocate() and destroy() before
> Yes, you have to. allocate() gives you raw memory with the correct size and
> alignment, but there is no object in it. To create the object in that
> memory, you need to construct() it. Similarly, destroy() invokes the
> destructor and deallocate() only, well, deallocates.

Excellent. That's one big headache I avoid. but:

>>foo* bar = static_cast<foo*>(get_allocator().allocate(1));
> new(bar) foo(args);
> or
> get_allocator().construct(bar, foo(args));

are these two expressions identical? I mean for any allocator (not just
std::allocator<T>). The former looks more efficient but less general
than the latter.

> No, scoped_* do not support allocators. Since they match raw pointers in
> size, they can keep no additional state such as an instance of, or a
> reference to, an allocator.

Ok, so that means i have to write my own scoped_allocator_ptr<T,
Allocator> I guess. No biggie, at least I don't have to rewrite shared_ptr.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at