如何查看初始化数组与未初始化数组所占用的内存 [英] How to see the memory occupied by initialised array vs uninitialised array

查看:297
本文介绍了如何查看初始化数组与未初始化数组所占用的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在按照Kip Irvine的"x86处理器的汇编语言"学习汇编程序设计.在3.4.12节中,作者声明:

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

.DATA?指令声明未初始化的数据.定义一个 大块未初始化的数据,.DATA?指令减少了 编译程序的大小.例如,以下代码是 有效声明:

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

另一方面,下面的代码生成一个已编译的程序 20,000字节大:

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, so I can see the effect of .data? for myself, but I'm not sure how it can be done.

推荐答案

在编译程序后,我想查看每个版本的代码的内存占用情况……

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.

这篇关于如何查看初始化数组与未初始化数组所占用的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆