The MASM Forum

General => The Campus => Topic started by: Lonewolff on March 16, 2016, 09:18:05 AM

Title: Variable initialisation
Post by: Lonewolff on March 16, 2016, 09:18:05 AM
Hi Guys,

What is the difference between .data and .data?

Wouldn't it be better to initialise all data to zero in .data instead of the latter? Or does this somehow affect executable size?


; Why not do this?
.data
hWnd DWORD 0
hHeap DWORD 0
msg MSG <0>

; Instead of doing this?
.data?
;hHeap DWORD ?
;hWnd DWORD ?
;msg MSG <?>


Thanks in advance :)
Title: Re: Variable initialisation
Post by: jj2007 on March 16, 2016, 02:30:22 PM
Quote from: Lonewolff on March 16, 2016, 09:18:05 AMOr does this somehow affect executable size?

It does indeed. Try yourself:
include \masm32\include\masm32rt.inc

.data
MyArray dd 250000 dup(0)

.code
start:
  MsgBox 0, str$(sizeof MyArray), "Bytes initialised:", MB_OK
  exit

end start
Title: Re: Variable initialisation
Post by: Lonewolff on March 16, 2016, 10:09:43 PM
So with '.data?' does this just allocate a space in RAM that can be filled in later on?
Title: Re: Variable initialisation
Post by: jj2007 on March 16, 2016, 10:47:57 PM
Exactly. It must be one of the *Alloc functions doing that during process startup.