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

為{幸葍}努か 提交于 2019-12-20 02:26:16

问题


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.



来源:https://stackoverflow.com/questions/44688293/how-to-see-the-memory-occupied-by-initialised-array-vs-uninitialised-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!