Getting core.exception.OutOfMemoryError error on allocating large arrays

John Colvin john.loughran.colvin at gmail.com
Sun Mar 3 08:09:44 PST 2013


On Sunday, 3 March 2013 at 16:02:31 UTC, Sparsh Mittal wrote:
>
>> Assuming double.sizeof==8 on your machine, You're requesting 
>> 1024*1024*1024*8*8 bytes = 68GB, do you have that much RAM 
>> available?
> You are completely correct, however in C, one could do:
>
> const long DIM = 1024L * 1024L * 1024L* 8L ;
> int  main() {
>    double signal[DIM];
>  }
>
> which runs fine. So, I was sort of looking for some solution 
> like this.

For a start, that's not equivalent. The C version is creating a 
static array, the D version is a dynamic one. The C version is 
allocated on the stack, the D on the heap.

I'm pretty certain the C version doesn't actually work as 68GB 
will have completely clobbered the stack.


More information about the Digitalmars-d-learn mailing list