Alligned gc allocation of struct

Stanislav Blinov stanislav.blinov at gmail.com
Sun Oct 7 13:06:40 UTC 2018


On Friday, 5 October 2018 at 20:41:15 UTC, Sjoerd Nijboer wrote:
> On Friday, 5 October 2018 at 14:55:04 UTC, Dennis wrote:
>> On Friday, 5 October 2018 at 10:03:35 UTC, Kagamin wrote:
>>> GC allocations are 16 bytes aligned.
>>
>> Is that an implementation detail or well-defined behavior?
>
> The GC_Allocator doesn't support alignedAllocate from the 
> IAllocate interface, which is kinda unfortunate.
> So I'm a little worried that this might change in the future.

I don't think you should rely on them being specifically 16-bytes 
aligned, if portability is your goal. The `GC`'s methods such as 
`GC.malloc` do indeed return an "aligned" memory block,  but 
that's about it as far as the spec goes. If, however, your target 
is specifically amd64 and SIMD, then you can safely assume the 
allocations are indeed always 16-bytes aligned.

On a side note, I think the `alignedAllocate` from the allocator 
interface in std.experimental was a poor API decision. Better 
have a specific allocator instance that allocates in an 
appropriate alignment requirement. If I ever see an allocator 
that supports allocating with both an unspecified alignment and 
arbitrary alignment, I'd steer clear from it even without looking 
at the implementation.


More information about the Digitalmars-d-learn mailing list