static array crashes my program

Olivier Pisano via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 5 02:11:42 PST 2015


On Saturday, 5 December 2015 at 09:49:06 UTC, ref2401 wrote:
> I want to create a static array large enough to store 1MB of 
> float values.
> What am I doing wrong?
> Here is a sample code with notes:
>
> void main(string[] args) {
> 	enum size_t COUNT = 1024 * 512 / float.sizeof; // works OK :)
> 	//enum size_t COUNT = 1024 * 512 * 2 / float.sizeof; // 
> constantly crashes :(
> 	float[COUNT] arr;
> 	writeln(arr.length);
> }
>
> DMD: 2069.2
> OS: Win 8.1 Pro

I suppose you overflow the stack.
I am not a Windows dev, but I suppose there is a linker option to 
increase the stack size.
Or you can try to use a global __gshared variable or allocate 
your array on the heap.


More information about the Digitalmars-d-learn mailing list