Title
pmr::memory_resource::do_allocate needs clarification
Status
new
Section
[mem.res.class]
Submitter
Jonathan Wakely

Created on 2021-11-12.00:00:00 last changed 26 months ago

Messages

Date: 2022-01-15.00:00:00

[ 2022-01-30; Reflector poll ]

Set priority to 3 after reflector poll.

Date: 2021-11-12.00:00:00

[mem.res.private] says that pmr::memory_resource::do_allocate returns "a pointer to allocated storage" and references [basic.stc.dynamic.allocation]. But it's not really clear which parts of [basic.stc.dynamic.allocation] define "allocated storage". pmr::memory_resource::allocate is not "an allocation function" and not a "replaceable allocation function", so "the value returned by a replaceable allocation function is a non-null pointer value" doesn't apply here, and neither does "different from any previously returned value".

Is pmr::memory_resource::allocate allowed to return a null pointer on success? Is it allowed to return the same address twice, without an intervening deallocation? What about if you call pmr::monotonic_buffer_resource::release(), is that a deallocation?

When discussed on the reflector the consensus was that returning null should not be allowed, it should throw an exception or return a valid dereferenceable pointer. The reference to [basic.stc.dynamic.allocation] doesn't work to specify this though, so we should restate the requirements without directly using the core wording for operator new.

It was also suggested that returning the same value should not be allowed without an intervening deallocation, but that "deallocation" should not only mean a call to deallocate on the resource, but include things like pmr::monotonic_buffer_resource::release(), and when a memory resource's destructor returns memory to an upstream resource.

History
Date User Action Args
2022-01-30 17:05:36adminsetmessages: + msg12314
2021-11-12 00:00:00admincreate