How to see the memory occupied by initialised arra

2019-02-24 18:07发布

问题:

I'm currently learning assembly programming by following Kip Irvine's "Assembly Language for x86 Processor". In section 3.4.12, the author states:

The .DATA? directive declares uninitialized data. When defining a large block of uninitialized data, the .DATA? directive reduces the size of a compiled program. For example, the following code is declared efficiently:

.data
smallArray DWORD 10 DUP(0) ; 40 bytes
.data?
bigArray DWORD 5000 DUP(?) ; 20,000 bytes, not initialized

The following code, on the other hand, produces a compiled program 20,000 bytes larger:

.data
smallArray DWORD 10 DUP(0) ; 40 bytes
bigArray DWORD 5000 DUP(?) ; 20,000 bytes

I want to see the memory footprint of each version of the code after the program is compiled, so I can see the effect of .data? for myself, but I'm not sure how it can be done.

回答1:

I want to see the memory footprint of each version of the code after the program is compiled…

The difference is in the size of the compiled executable, not the size of its image in memory when it's being executed.

In brief: most modern operating systems have a way for an executable to declare a memory region as "zero filled". The executable only needs to say how big the region is, so it's much smaller than if it included a bunch of literal zeroes for that region.