Boost logo

Boost :

Subject: Re: [boost] [container] Implemented Polymorphic Memory Resources
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2015-09-08 08:23:28


On 08.09.2015 14:57, Ion Gaztañaga wrote:
> On 08/09/2015 13:26, Andrey Semashev wrote:
>> I see that new_delete_resource and null_memory_resource instances have
>> static storage duration. I suppose, it means that containers using these
>> resources cannot be used in global constructors/destructors (including
>> the global variables of their type)? This is a serious limitation IMO,
>> as people often use strings and containers globally.
>
> Good point. The specification says they return:
>
> "A pointer to a static-duration object of a type"

Yes, and to my mind this has to be fixed before it goes into the
standard. Or at the very least, the problem has to be acknowledged.

[Note about the proposal. Ideally, I would have preferred it to not use
virtual functions at all and make the base class contain the free
function pointers taking 'this' and the rest arguments. It would be more
efficient in run time and, what's more important, it would allow for
static initialization of the standard memory resource instances. I
realize though that this would complicate the other (more complex)
resource implementation as it would have to manually fill the pointers
on construction, so it is unlikely that this will be done in the standard.]

> Both classes are empty but we need to initialize the virtual function
> pointer. We could make some lazy initialization via placement new as the
> destructor is trivial and just avoid the explicit placement destruction.
> Could this be acceptable?

It looks ok to me. You might have a little problem with the default
resource pointer, which should now indicate that the new_delete_resource
is not yet constructed. You can do it by making it nullptr initially and
checking for it in get_default_resource().


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk