Thread overview
[Issue 21136] N sized array takes kN bytes in executable file
Aug 08, 2020
KytoDragon
Aug 08, 2020
Raoof Hajibagheran
Aug 08, 2020
KytoDragon
Aug 08, 2020
Raoof Hajibagheran
Aug 08, 2020
Raoof Hajibagheran
Aug 11, 2020
Raoof Hajibagheran
Mar 25, 2022
RazvanN
August 08, 2020
https://issues.dlang.org/show_bug.cgi?id=21136

KytoDragon <kytodragon@e.mail.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kytodragon@e.mail.de

--- Comment #1 from KytoDragon <kytodragon@e.mail.de> ---
These sizes all look correct.
byte, bool and int initialize to zero, so they don't need to be explicitly
stored in the resulting executable. 1000000 chars need 1000000 bytes, floats
use 4 bytes each so need 4000000 bytes total and double use 8 bytes each,
resulting in a total of 8000000 bytes.
The remaining ~16k bytes are just the code and metadata of the executable.

--
August 08, 2020
https://issues.dlang.org/show_bug.cgi?id=21136

--- Comment #2 from Raoof Hajibagheran <raoofha@yahoo.com> ---
sorry to bother but how can I prevent float and double and char arrays from appearing in the output?

--
August 08, 2020
https://issues.dlang.org/show_bug.cgi?id=21136

--- Comment #3 from KytoDragon <kytodragon@e.mail.de> ---
You can have them be zero initialized by assigning zero to the array:

double[1000000] = 0;

Do note that this only decreases the size of the executable. Once the program is loaded into memory these array will obviously be expanded to their full size.

--
August 08, 2020
https://issues.dlang.org/show_bug.cgi?id=21136

--- Comment #4 from Raoof Hajibagheran <raoofha@yahoo.com> ---
I know that but it doesn't work. my assumption was that when you don't define default values for variables the compiler doesn't put them in the output file. but in this case it doesn't work whether you init to zero or not.

--
August 08, 2020
https://issues.dlang.org/show_bug.cgi?id=21136

--- Comment #5 from Raoof Hajibagheran <raoofha@yahoo.com> ---
and another issue is that I'm only defining struct S and never use it but it takes space anyway. but this is a minor issue for me.

--
August 11, 2020
https://issues.dlang.org/show_bug.cgi?id=21136

--- Comment #6 from Raoof Hajibagheran <raoofha@yahoo.com> ---
setting variables to void avoid this problem.
but the output file size is still large I don't know why, I set all the
variables to void.

--
March 25, 2022
https://issues.dlang.org/show_bug.cgi?id=21136

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |INVALID

--- Comment #7 from RazvanN <razvan.nitu1305@gmail.com> ---
Since D initializes all variables by default, it needs to store the initializer. Yes, void initialization is used to not store the initializer. This is all according to the spec, there is no bug here.

--