Runtime?

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Wed May 24 08:07:42 PDT 2017


On 5/24/17 6:34 AM, Moritz Maxeiner wrote:
> On Wednesday, 24 May 2017 at 07:54:04 UTC, Wulfklaue wrote:
>> Great ... accidentally pressed send.
>>
>> So my question was:
>>
>> Why does even a simple empty empty statement like this, compiled with
>> DMD, show under windows a almost 1.7MB memory usage?
>
> Because the garbage collector (GC) allocates a sizable chunk of memory
> from the operating system at program startup, from which it then in turn
> allocates memory for you when you use things like dynamic closures, `new
> XYZ`, etc.

Note, you can usually allocate close to the entire address space, but if 
you never access it, it's not actually used in the RAM of your computer. 
So it's possible D is pre-allocating a bunch of space from the OS, but 
it's not actually consuming RAM.

However, I don't know the true answer. It may actually be 1.7MB of 
"bookeeping", but I doubt that. The GC structures aren't *that* large, 
I'd expect at most 10 pages for the small-chunk bins, and a few more for 
bits. Possibly the static segment is large, but 1.7 MB is around 400+ 
pages. It's likely that most of that is just a pre-allocation of a large 
continuous space "just in case", but it's not actually wired to RAM yet.

-Steve


More information about the Digitalmars-d mailing list