Setting a hard limit on slice size, is this possible?
Tejas
notrealemail at gmail.com
Fri Aug 6 17:25:24 UTC 2021
On Friday, 6 August 2021 at 10:50:19 UTC, james.p.leblanc wrote:
> I am aware of the "capacity" concept with slices.
>
> But, I would like to know if it is possible to set a
> hard limit on a slice size.
>
> I prefer it to error and crash instead of a doing an
> extension or reallocation.
>
> I understand my question screams of "convoluted
> thinking". But, I need to align my slice according to
> certain criteria.
>
> (Alternatively, I could use an array ... if I could
> align that according to criteria known at compile
> time. Is this possible?).
>
> I have a working solution (ugly trick, maybe is a
> better description) to align my slice as desired.
>
> But, the solution would be more robust if I could
> guarantee that the slice is never moved in memory.
>
> Any thoughts, hints, etc are welcome!
>
> James
Okay we were overthinking the solution.
Just use a static array
```d
int[your_max_length]/*or whatever type*/ var;
```
You're good to go!
I almost feel stupid now lol
More information about the Digitalmars-d-learn
mailing list