[PATCH] D47111: <experimental/memory_resource>: Implement monotonic_buffer_resource.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 28 19:48:05 PDT 2018


EricWF added inline comments.


================
Comment at: src/experimental/memory_resource.cpp:237
+
+    void *result = __res_->allocate(aligned_capacity, align);
+    __monotonic_buffer_header *header = (__monotonic_buffer_header *)((char *)result + aligned_capacity - header_size);
----------------
Quuxplusone wrote:
> For reference, here is where we ask the upstream for a block aligned according to the user's `align`.
> It occurs to me that the upstream might not be able to satisfy such a request (actually, `new_delete_resource` works that way for me because libc++ doesn't support aligned new and delete on OSX), which would make the upstream throw `bad_alloc`. We handle this by passing along the exception. We //could// conceivably handle it by retrying with
> ```
>     aligned_capacity += align;
>     __res_->allocate(aligned_capacity, alignof(max_align_t));
>     header->__alignment_ = alignof(max_align_t);
> ```
> but I'm not sure that that's any of `monotonic_buffer_resource`'s business. Happy to make the patch if you think it ought to be.
I was initially thinking of storing `lg(align)`.


Repository:
  rCXX libc++

https://reviews.llvm.org/D47111





More information about the cfe-commits mailing list