PR libstdc++/70940 optimize pmr::resource_adaptor for allocators using malloc
authorJonathan Wakely <jwakely@redhat.com>
Mon, 23 Jul 2018 19:40:28 +0000 (20:40 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 23 Jul 2018 19:40:28 +0000 (20:40 +0100)
commit2d6c8eea1d7ae5b3b2b3c2508f78de918c73f4c4
tree2db36a97ddc96b86ee3c32f89c5cfb365cbe2c5a
parent651a79532c8e87ac096419d9852a295f9e284fe4
PR libstdc++/70940 optimize pmr::resource_adaptor for allocators using malloc

pmr::resource_adaptor can avoid allocating an oversized buffer and doing
manual alignment within that buffer when the wrapped allocator is known
to always meet the requested alignment. Specifically, if the allocator
is known to use malloc or new directly, then we can call the allocator
directly for any fundamental alignment.

PR libstdc++/70940
* include/experimental/memory_resource
(__resource_adaptor_common::_AlignMgr::_M_unadjust): Add assertion.
(__resource_adaptor_common::__guaranteed_alignment): New helper to
give maximum alignment an allocator guarantees. Specialize for known
allocators using new and malloc.
(__resource_adaptor_imp::do_allocate): Use __guaranteed_alignment.
(__resource_adaptor_imp::do_deallocate): Likewise.
* testsuite/experimental/memory_resource/new_delete_resource.cc:
Check that new and delete are called with expected sizes.

From-SVN: r262935
libstdc++-v3/ChangeLog
libstdc++-v3/include/experimental/memory_resource
libstdc++-v3/testsuite/experimental/memory_resource/new_delete_resource.cc