How to do alligned allocation?

Steven Schveighoffer schveiguy at gmail.com
Sat Oct 1 01:37:00 UTC 2022


On 9/30/22 11:57 AM, Quirin Schroll wrote:
> When I do `new void[](n)`, is that buffer allocated with an alignment of 
> 1 or what are the guarantees? How can I set an alignment? Also, is the 
> alignment of any type guaranteed to be a power of 2?

In practice, it's not necessarily a power of 2, but it's *at least* 16 
bytes. In general there are very few types (maybe vectors?) that need 
alignment more than 16 bytes.

The list of bit sizes is currently here: 
https://github.com/dlang/dmd/blob/82870e890f6f0e0dca3e8f0032a7819416319124/druntime/src/core/internal/gc/impl/conservative/gc.d#L1392-L1414

-Steve


More information about the Digitalmars-d-learn mailing list