windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server https://softhier.com/ instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

Compiled file is too large [202493852 bytes] error from on-line submission

Asked By: Anonymous

While using a 2-D array, I tried using a static array assigning -1 to it’s first element:

int dp[5001][5001] = {-1};   //setting dp[0][0] to -1
int calc(int i, int j){
    //Some operations are happening here which utilize dp array.
}
int main(){
   cout << calc(0,0);
}

When I submit this code-snippet as a solution online, I get Can't compile file: Compiled file is too large [202493852 bytes].

But, when I just gave it a try by setting the value of dp in main()

int dp[5001][5001];
int calc(int i, int j){
    //Some operations are happening here which utilize dp array.
}
int main(){
   dp[0][0] = -1;
   cout << calc(0,0);
}

The above snippet was successfully accepted and compiled.

Can someone explain why this is happening?


Solution

Answered By: Anonymous

When you declare a static array with an initializer, like

int dp[5001][5001] = {-1};

the whole array is put into a data section of the executable file. Its size is (5001×5001=25010001) × sizeof(int) of your compiler. If sizeof(int)==8, then the size of the array in bytes, 200080008, comes close to the limit you cited. There is other stuff in the binary, in the end.

On the other hand, an array without an initializer from the second example

int dp[5001][5001];

is not allocated any data space in the executable file; instead, there is just a small record that tells the loader to allocate a zero-initialized block of memory of this size in the process’ address space when it starts.

This optimization is not mandatory, but both ELF and Windows PE binaries use it. The initialized data segment is typically called .data, and the uninitialized .bss.


A tiny hands-on experiment to show the concept¹:

// Save me as bss.cc
int without_initializer[10000][10000];      // 100 million elements.
int with_initializer[1000][1000] = { 42 };  // 1 million elements.

/*
Run and see:
$ c++ -c -o bss.o bss.cc
$ ls -l bss.o
-rw-r--r-- 1 kkm kkm 4001008 2021-05-18 06:00:19 bss.o
$ objdump -h bss.o
bss.o:     file format elf64-x86-64
Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00000000  0000000000000000  0000000000000000  00000040  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         003d0900  0000000000000000  0000000000000000  00000040  2**5
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          17d78400  0000000000000000  0000000000000000  003d0940  2**5
                  ALLOC
  3 .comment      0000001d  0000000000000000  0000000000000000  003d0940  2**0
                  CONTENTS, READONLY
$ rm bss.cc bss.o
*/

The .data section has the size 0x3d0900=4000000 bytes. Apparently, this compiler’s sizeof(int) is 4. It also has the LOAD flag, which means that it must be loaded from the file, as is well explained in the linked answer.

ls(1) shows that the object file size is just a little larger than the same 4000000 bytes, with a bit of extra space taken by headers and the little .comment section, probably identifying the compiler (objdump(1) can dump its contents, if you’re so curious).

The .bss section has the size 0x17d78400=400000000, exactly equal sizeof(without_initializer). It has the ALLOC flag to tell the loader that it must be in the process’ address space, but not the LOAD flag, which means there is nothing to load from the file.

You may note that the .bss section occupies exactly 0 bytes in the file: it’s offset and that of the following .comment section are both 0x003d0940.

¹ Using Linux commands and its ELF format. On Windows, use cl /c bss.cc then dumpbin /headers bss.obj from the Native Tools command prompt if you have Visual Studio handy.

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno