Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 03, 2013 Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
I am running enum long DIM = 1024L * 1024L * 1024L* 8L ; void main() { auto signal = new double[DIM]; } and getting core.exception.OutOfMemoryError error. One option is to use short/int, but I need to use double. Also, on using large arrays, computer becomes slow. Is there no workaround at all, so that I can work on large arrays? Please let me know. |
March 03, 2013 Re: Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sparsh Mittal | On Sunday, 3 March 2013 at 14:05:02 UTC, Sparsh Mittal wrote:
> I am running
>
>
> enum long DIM = 1024L * 1024L * 1024L* 8L ;
> void main() {
> auto signal = new double[DIM];
> }
>
>
> and getting core.exception.OutOfMemoryError error. One option is to use short/int, but I need to use double. Also, on using large arrays, computer becomes slow.
>
> Is there no workaround at all, so that I can work on large arrays? Please let me know.
Assuming double.sizeof==8 on your machine, You're requesting 1024*1024*1024*8*8 bytes = 68GB, do you have that much RAM available?
|
March 03, 2013 Re: Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin |
> 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.
|
March 03, 2013 Re: Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Sunday, 3 March 2013 at 15:52:49 UTC, John Colvin wrote:
> On Sunday, 3 March 2013 at 14:05:02 UTC, Sparsh Mittal wrote:
>> I am running
>>
>>
>> enum long DIM = 1024L * 1024L * 1024L* 8L ;
>> void main() {
>> auto signal = new double[DIM];
>> }
>>
>>
>> and getting core.exception.OutOfMemoryError error. One option is to use short/int, but I need to use double. Also, on using large arrays, computer becomes slow.
>>
>> Is there no workaround at all, so that I can work on large arrays? Please let me know.
>
> Assuming double.sizeof==8 on your machine, You're requesting 1024*1024*1024*8*8 bytes = 68GB, do you have that much RAM available?
Depending on your OS, you will of course have to take in to account page file limits and swap partition sizes. Nonetheless, 68GB is a huge amount of memory to have in a single array, that's 8.6 billion numbers. In reality I doubt you will need that many.
|
March 03, 2013 Re: Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | Thanks. Yes, you are right. I will change my program. |
March 03, 2013 Re: Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sparsh Mittal | 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.
|
August 18, 2013 Re: Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | on my machine (core i7, 16 gb ram, win7/64) next code written core.exception.OutOfMemoryError: enum long size= 1300_000_000; auto arr = new byte[size]; but next code work fine: enum long size= 1300_000_000; byte * p = cast(byte *) malloc(size); i compiled in 64 bit mode i use keys: "dmc -c -m64 test.d" |
August 18, 2013 Re: Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to zorran | On Sunday, 18 August 2013 at 12:07:02 UTC, zorran wrote:
> on my machine (core i7, 16 gb ram, win7/64)
> next code written core.exception.OutOfMemoryError:
> enum long size= 1300_000_000;
> auto arr = new byte[size];
>
> but next code work fine:
> enum long size= 1300_000_000;
> byte * p = cast(byte *) malloc(size);
>
> i compiled in 64 bit mode
> i use keys: "dmc -c -m64 test.d"
Interesting... What happens if you use core.memory.GC.malloc?
|
August 18, 2013 Re: Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin |
> Interesting... What happens if you use core.memory.GC.malloc?
enum long size= 1300_000_000;
byte * p = cast(byte *) malloc(size);
for(int i=0; i<size; i++)
p[i]=1;
ulong sum=0;
for(int i=0; i<size; i++)
sum += p[i];
writef("%d ", sum); // here written 1300000000
|
August 18, 2013 Re: Getting core.exception.OutOfMemoryError error on allocating large arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to zorran | On Sunday, 18 August 2013 at 12:40:42 UTC, zorran wrote: > >> Interesting... What happens if you use core.memory.GC.malloc? i am using in sample import std.c.stdlib; GC.malloc also written core.exception.OutOfMemoryError |
Copyright © 1999-2021 by the D Language Foundation