On Tue, 23 Feb 2010 08:36:04 -0500, bearophile <[email protected]> wrote:

The Java VM has a limit of the amount of memory it allocates from the heap. So is it useful to add a way to specify a similar limit for D2 programs (especially ones made by safe module)? This limit can be given to the D GC heap (and maybe to the C heap too).

This limit can just be a compile-time constant given to the compiler, this produces a binary that has a limit of 200 MB of heap:
dmd -mlimit=200mb foo.d
The situation gets less simple if you want to change such limit after the program is already compiled, I don't know of simple ways to do it. Maybe a second program can be used for that:
gclimiter -mlimit=100mb foo.exe

The GC is open source. Submit a patch if you want. DMD is not in charge of the GC, it is runtime code, I don't think we need a specific option for it. I think it can be runtime-decided, and the option passed via your program initialization. I.e.:

void main()
{
GC.memlimit = 200_000_000; // 200 MB
...
}

I also don't think that limits to memory are too important for most applications, only for specific ones.


-Steve

Reply via email to