www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - "Memory allocation failed" on big array

reply urned utt <urned utt.mail> writes:
Hello.

having about 6 Gb free RAM, trying to execute:

```d
string[] dic;
	
for (int i = 0; i < 100_000_000; i++)
{
	
	dic ~= "just a word number "~to!string(i);

	if (i%1_000_000 == 0)
	{
		writef("processed line %s: %s\n", format("%,3d", i), 
format("%,3d", dic.length));
	}
}

```

got an error:
"processed line 32,000,000: 32,000,001
core.exception.OutOfMemoryError src\core\lifetime.d(126): Memory 
allocation failed"

app used is about 1.6 Gb, more than 4 stays free.

1. What is happened, why dynamic array have mem limit? For 
example, golang uses all free memory that it can.
2. How to fix this?
3. (optional) How to display memory usage? Cannot find function 
for this.

Thanks.
Jul 20 2022
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
My guess is you are compiling to 32bit and the GC tries to 
reserve >4gb wich it can't, therefore out of memory

Compiling to 64bit with: `dmd -m64 -run test.d` works no problem
Jul 20 2022
parent urned utt <urned utt.mail> writes:
Big thank.


Switch to /bin64 and now works until full memory using.
Jul 20 2022