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

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Aug 6 18:17:09 UTC 2021


On Fri, Aug 06, 2021 at 06:02:01PM +0000, james.p.leblanc via Digitalmars-d-learn wrote:
[...]
> However, do NOT feel stupid ... the motivation behind why
> I cannot use a standard int[your_max_length] (in other words,
> use a static array), is because I need to do a specified
> memory alignment (known at compile time) on my slice, or array.

I've never actually tried this myself, but have you looked into the
`align` keyword in the D spec?  I'm not 100% sure whether it can be
applied to static arrays (or arrays in general) but it might be worth a
look.


> I understand that neither a slice or an array is capable to doing
> an arbitrary memory alignment.  (But, perhaps I am wrong about this
> ...)
> 
> I believe structs can be aligned, but need to learn more about the
> speicific of that.

One thing that might help you is if you had a struct with the
appropriate align(...) declaration that wraps around your array
elements. Pretty sure that would guarantee the alignment of array
elements, which in turn should guarantee alignment of the array as a
whole.


T

-- 
It is the quality rather than the quantity that matters. -- Lucius Annaeus Seneca


More information about the Digitalmars-d-learn mailing list