How to save RAM in D programs (on zero initialized buffers): Reloaded

Marco Leise Marco.Leise at gmx.de
Tue Feb 7 20:46:38 PST 2012


Am 08.02.2012, 04:40 Uhr, schrieb Jose Armando Garcia <jsancio at gmail.com>:

> Special? What do you mean by special? Most OS use Virtual Memory so
> sure they can say here is a page and yet not have that page backed by
> physical memory. To my knowledge, they can only do this if the
> allocated memory points to an unmapped page. I doubt this is the case
> in non-trivial programs.

Yes, special. Like, say, you fork a process on Unix. Instead of copying  
all the uses memory, the processes share the same pages in read-only,  
copy-on-write mode. As soon as one of the processes writes to a memory  
page it is duplicated. The same is true for the 'zero page'. Just that  
there is one for the whole system and it can have a zillion references to  
it: http://en.wikipedia.org/wiki/Copy-on-write <- Look for calloc
So the page can even be mapped and read without increasing the memory  
footprint, as I understand it.


More information about the Digitalmars-d mailing list