I’m working on a 32-bit windows application that can occasionally run out of memory (the 2GB of virtual address space). When I look at how the virtual memory is allocated using WinDbg or VMMap, I notice a dll image that is taking 85 MB of vitual memory space. To be specific, 84 MB of this is in the “.data” section, and has “Copy on write” protection. When I look on the harddrive, however, the dll is only 81 KB.
How could the dll image be over 1000 times larger in virtual address space than on disk? Note that I am only asking about the “Image”, not the heaps or stacks, or mapped memory, just the image – I realize that of course the heaps, stacks, mapped memory, etc. will be additional.
Try creating an empty .dll and add this at file scope:
That should declare an entry in the .bss section. That is a section in the image that defines zero initialized data. Since that data is initialized to zero, it is a fairly simple optimization to just declare how big it should be when running instead of storing a bunch of zeros on disk.