On Friday, 13 November 2015 at 15:49:01 UTC, Ish wrote:

foreach (i; 0..5) {
  immutable int j = i;
  etc.
}
I want each j to be assigned separate memory so that it can be passed to a calle function and not overwritten by next value of i in foreach()??

Just like in C, you'll have to allocate storage for each object you create.

    immutable int* j = new immutable int(i);

Though if you use `new`, you can let the GC free them.

But if the data is immutable, then there's no point in allocating separate objects for each number, since they can't be changed.

Reply via email to