what is going on here?

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Jan 4 23:34:41 UTC 2022


On Tue, Jan 04, 2022 at 10:53:50PM +0000, forkit via Digitalmars-d-learn wrote:
[...]
> // ----
> 
> module test;
> void main(){ static char[2147483646] arr; }
> 
> // ----

I bet you it's the same problem I found a couple of years ago, where the
compiler translates the above code to something that individually
initializes every element of the array. I.e., there would be 2.1 billion
assignments, one for each element in the array.  Of course, afterwards
the optimizer would merge them into something saner, but while the
compiler is unfolding all those assignments, its memory usage would
obviously skyrocket.

Try setting `arr = void;` to see if it makes a difference. If it does,
it's probably the same problem.


T

-- 
Skill without imagination is craftsmanship and gives us many useful objects such as wickerwork picnic baskets.  Imagination without skill gives us modern art. -- Tom Stoppard


More information about the Digitalmars-d-learn mailing list