C++ Logo

sg10

Advanced search

Re: [SG10] Over-aligned dynamic allocation

From: Jason Merrill <jason_at_[hidden]>
Date: Mon, 18 Jul 2016 12:35:08 -0400
On Wed, Jun 22, 2016 at 1:07 AM, Daniel Krügler
<daniel.kruegler_at_[hidden]> wrote:
> 2016-06-22 6:04 GMT+02:00 Nelson, Clark <clark.nelson_at_[hidden]>:
>>> I can imagine that the macro would also be used by people who
>>> replace the global operator new, and who would also replace the
>>> aligned version if it were present.
>>
>> That's a good point. It would also serve to indicate whether
>> "std::align_val_t" were available as a type name.
>>
>> Would anyone else like to weigh in in one direction or the other?

I think we definitely want some macro for users to be able to check; I
don't feel strongly about having a feature test macro in addition to
the STDCPP macro.

I've previously written

template <class T, class...Args>
T* aligned_new(Args&&... args)
{
  void *p = aligned_alloc (alignof (T), sizeof (T));
  return new (p) T(std::forward<Args>(args)...);
}

and I can avoid the use of C11 aligned_alloc when C++17 aligned new is
available.

Jason

Received on 2016-07-18 18:35:30