Memory allocation problem

Jeremie Pelletier jeremiep at gmail.com
Sat Aug 8 20:47:32 PDT 2009


bearophile Wrote:

> In a small program on Windows XP I have to allocate a large chunk of RAM, about 1847 MB of RAM. This PC has 2 GB RAM. So I use std.c.stdio.malloc(), with DMD v1.042 (or v2.031). But it's not able to allocate it, and produces at runtime:
> Error: Access Violation
> 
> An equal program written in C and compiled with GCC, that allocates the same amount of memory using malloc, is able to run (with just a little hard disk trashing at the beginning).
> Do you know why DMD doesn't allow me to allocate more RAM, and can this be fixed?
> 
> Bye,
> bearophile

i just did the test on my 6Gb ram laptop, it failed, the exception comes from the error handling crashing on OutOfMemory exceptions (I think).

Your C program probably compiled in 64bit, which has MUCH more room for virtual memory.

DMD only compiles 32bit binaries so far, and the virtual memory it can map for a single process is 4Gb, 2 of which are reserved for shared system memory.

What that means is, when you allocate memory, even if you DO have 2Gb available in ram or pagefile, you may not have enough contiguous free pages of virtual memory to map the allocation, 64bit applications rarely hit that wall anymore.

You could always try and stream the memory and allocate the minimum required, and work on it one slice at a time.



More information about the Digitalmars-d mailing list