Where does the Standard say that every distribution returned by `new` is aligned with` std :: max_align_t`?

In this video , at about 6.39, the presenter seems to say that he newalways returns memory aligned to std::max_align_tthat, because he operator newdoes not know anything about the type of allocated variable. That is, the compiler must choose the very lowercase alignment. But I can not find it in the Standard.

The host also says that this rule does not apply when newused to allocate arrays charor unsigned char. In this case, alignment depends on the size. But it was not clear to me either.

+4
source share
1 answer

This is in [basic.stc.dynamic.allocation] / 2:

The distribution function is trying to allocate the requested amount of memory. If successful, it should return the start address of the storage unit, the length of which in bytes should be no less than the requested size. [...] The returned pointer must be properly aligned so that it can be converted to a pointer to any complete object type with a fundamental alignment requirement (3.11), and then used to access the object or array in a dedicated storage (until the repository will not be explicitly released by calling the corresponding release function). [...]

+3
source

Source: https://habr.com/ru/post/1611126/


All Articles