How to refer to different sized static arrays

Ferhat Kurtulmuş aferust at gmail.com
Sat Feb 8 19:48:06 UTC 2020


On Saturday, 8 February 2020 at 08:22:46 UTC, Adnan wrote:
> Just a foreword, this is for learning purposes, hence I am not 
> using the dynamic array or Array!T.
>
> I have a structure that maintains a heap allocated sized array 
> inside.
>
> struct LifoStack(T) {
>   T[?] data;
> }

T[N] is a static array and N must be a compile time constant such 
as a literal, an enum, or a template parameter. So you cannot 
change its size. This is the distinct difference between static 
and dynamic arrays.

> Also, how can I create runtime-determined sized fixed array in 
> the heap?

The heap is for dynamic allocations, I don't understand why to 
store a fixed-length array in the heap. Why not just to make data 
dynamic array?


More information about the Digitalmars-d-learn mailing list