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
>>deallocate().
>
> 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.

Mark


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net