[PATCH] D47358: <experimental/memory_resource>: Implement {un, }synchronized_pool_resource.

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 19 15:17:33 PDT 2018


Quuxplusone updated this revision to Diff 151984.
Quuxplusone added a comment.
Herald added a subscriber: mgrang.

Bugfix and shrink {un,}synchronized_pool_resource.

The old implementation was severely broken in two ways:

- It accidentally sometimes trusted the user's `bytes` and `align` arguments to `do_deallocate`, which didn't match the `bytes` and `alignment` stored in the actual ad-hoc chunk header. The new test case catches this bug.

- It relied on pointer comparison (undefined behavior) to test whether the user-supplied pointer belonged to each chunk in turn. Fortunately this is unnecessary. The new code follows Boost.Container by keeping just one list of "vacancies" per pool (not one per chunk, as I'd been doing). The new code is faster (deallocation is now `O(1)` not `O(chunks-in-this-pool)`), smaller (there are `O(pools)` free-list pointers instead of `O(chunks)`), and avoids undefined behavior.


Repository:
  rCXX libc++

https://reviews.llvm.org/D47358

Files:
  include/experimental/memory_resource
  src/experimental/memory_resource.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.ctor/ctor_does_not_allocate.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.ctor/sync_with_default_resource.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.ctor/unsync_with_default_resource.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/equality.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/sync_allocate.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/sync_allocate_overaligned_request.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/sync_allocate_reuse_blocks.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/sync_deallocate_matches_allocate.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_allocate.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_allocate_overaligned_request.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_allocate_reuse_blocks.pass.cpp
  test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_deallocate_matches_allocate.pass.cpp
  test/std/experimental/memory/memory.resource.pool/pool_options.pass.cpp
  test/support/count_new.hpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47358.151984.patch
Type: text/x-patch
Size: 48135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180619/03f38354/attachment-0001.bin>


More information about the cfe-commits mailing list