如何查看初始化数组与未初始化数组占用的内存

How to see the memory occupied by initialised array vs uninitialised array

我目前正在按照 Kip Irvine 的 "Assembly Language for x86 Processor" 学习汇编编程。在第 3.4.12 节中,作者指出:

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

我想看看程序编译后各版本代码的内存占用情况,所以可以自己看看.data?的效果,但是不知道怎么实现.

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

不同之处在于编译后的可执行文件的大小,而不是执行时其在内存中的图像大小。

简而言之:大多数现代操作系统都有一种方法让可执行文件将内存区域声明为 "zero filled"。可执行文件只需要说明该区域有多大,因此它比包含该区域的一堆文字零要小得多。