Where is the runtime memory overhead from?

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Thu Apr 12 01:30:02 PDT 2012


Consider this program:

// blank.d
void main() {
    while(true) {} // Poor man's sleep ;)
}

>dmd blank.d

On WinXP 32-bit DMD 2.058, if I run that, task manager tells me it's using 
8816k of memory.

*Note: I'm not complaining.*

I just wanted to ask if anyone knows what that overhead is primarily from?

Just from druntime/phobos being statically linked? OS process overhead? Some 
DLLs that are implicitly used? (But I assume DLLs aren't counted in that 
memory usage figure...) Etc... I don't think it's from the raw exe file 
itself being loaded into mem, because that's only 143k.

As a frame of reference, if I change "true" to "1" and compile with DMC 
(instead of DMD), then it only uses 1265k ram. (The exe file is smaller too, 
but *that* I'm sure is just because of phobos/druntime being statically 
linked.)

The reason I'm asking is I'm making a few minor edits to my "Have Your 
Efficiency, and Flexibility Too" article, and I'm tempted to breifly point 
out that the 10% decrease in memory usage with the "handcrafted version" is 
better than it sounds because most of that 10MB ram is just overhead. But 
saying that D programs have 8-9MB runtime overhead probably sounds very bad, 
so I'm not sure I want to do it if I can't provide a (breif) "Don't worry! 
Because..."

(Although I may still just skip the whole mention altogether and just leave 
it at "10% decrease in memory - and now on to the next section" and not even 
worry about it. Whatever. In any case, I am at least curious.)




More information about the Digitalmars-d mailing list