4

In Kip Irvines book I came across the following :

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 followingcode is declared efficiently:

.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

bigArray DWORD 5000 DUP(?) ; 20,000 bytes

What exactly is the .data? directive doing under the hood in the above example to make the program 20k smaller.

Community
  • 1
  • 1
Ted
  • 345
  • 5
  • 18

1 Answers1

7

The uninitialized data need not be in the compiled binary, just a byte count that the OS loader allocates at run-time when executing your program.

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
  • When you say "OS loader allocates at runtime ", What you seem to be saying is that the .DATA? directive somehow tells the OS loader to perform dynamic memory allocation when it loads the binary. What I would have thought is that the binary itself contains some initialization code block that is run before your code section, and in this initialization block it effectively does a malloc or new. – Ted Aug 21 '11 at 12:30
  • 3
    No, it is a core capability of the executable file format. Use dumpbin.exe /headers to see the sections in the file. – Hans Passant Aug 21 '11 at 13:53
  • 1
    Hey Jens/Hans I was just reviewing all my questions and wanted to say thx for the answer, I just realized I didn't accept it....it's two years to late so forgive me and I'll buy you a beer/wine/coffee/tea when you're in London next! :-) – Ted Mar 09 '14 at 21:20