Could exe be smaller than its largest declared buffer?

I ask:

#include <string.h>

using namespace std;

int main()
{
    unsigned char file[512000];
    unsigned char key[512000];
    for(int i = 0; i < 512000; i++)
            file[i] = key[i];
    return 0;
}

When I compile this with cl.exe on Windows, I get an executable file about 31 KB in size. The buffers themselves are 500 kb. How does that make sense? Will part of it be allocated to a bunch? If I initialized them with data, would the size be correct?

+3
source share
5 answers

In this case, the buffers will be allocated on the stack space program at runtime. There is no need for them to be statically embedded in the file exe.

+12
source

, (, ), , . , , , .

+5

, . , . , , .

+1

, . .exe ( ).

0

To embed in executable binary code, only non-zero initialization data is required; these are unified arrays.

0
source

Source: https://habr.com/ru/post/1786002/


All Articles