Setting a hard limit on slice size, is this possible?

Paul Backus snarwin at gmail.com
Sat Aug 7 19:07:04 UTC 2021


On Saturday, 7 August 2021 at 15:41:24 UTC, Tejas wrote:
> On Saturday, 7 August 2021 at 15:21:01 UTC, Paul Backus wrote:
>>
>> The issue with `align` attributes being ignored for stack 
>> variables is apparently a known bug, first reported in 2016: 
>> https://issues.dlang.org/show_bug.cgi?id=16098
>>
>> The issue with `align` attributes being ignored by `new` is 
>> also a known bug, and was also first reported in 2016: 
>> https://issues.dlang.org/show_bug.cgi?id=16508
>
> Oh wow, and here I thought I was being smart :(
>
> So, how can we work around this without assembly language 
> magic? I'm illiterate at assembly.

For stack allocations, you can use the workaround in [Vladimir 
Panteleev's comment][1]  (ignoring the ASM part, which is 
unrelated to alignment).

For heap allocations, I guess the easiest way would be to use 
[`AlignedMallocator`][2] from `std.experimental.allocator`.

[1]: https://issues.dlang.org/show_bug.cgi?id=16098#c3
[2]: 
https://phobos.dpldocs.info/std.experimental.allocator.mallocator.AlignedMallocator.html


More information about the Digitalmars-d-learn mailing list