is the array literal in a loop stack or heap allocated?
Steven Schveighoffer
schveiguy at gmail.com
Fri Oct 13 03:37:42 UTC 2023
On 10/10/23 10:54 PM, mw wrote:
> Hi,
>
> I want to confirm: in the following loop, is the array literal `a` vs.
> `b` stack or heap allocated? and how many times?
ask the compiler:
```d
void main() @nogc {
int[2] a;
int[] b;
int i;
while(++i <=100) {
a = [i, i+1]; // array literal
//b = [i, i+1]; // yes, this allocates, had to comment it out
}
}
```
-Steve
More information about the Digitalmars-d-learn
mailing list