Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-11-18 08:54:16


Mark A. Gibbs wrote:
> Peter Dimov wrote:
>
>>> 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.

The short answer is that nobody knows, as allocators are underspecified
(standardese for "a mess"). The standard says, in Table 32 - Allocator
requirements, that a.construct(p, t) must have the effect new((void*)p)
T(t). In addition, there is no guarantee that the standard library
containers will bother to call construct() and not use placement new
directly. So the choice which form to use is up to you. ;-)


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