delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/05/21:39:46

Sender: nate AT cartsys DOT com
Message-ID: <36197329.262A517E@cartsys.com>
Date: Mon, 05 Oct 1998 18:32:25 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.05 [en] (X11; I; Linux 2.0.35 i486)
MIME-Version: 1.0
To: george DOT foot AT merton DOT oxford DOT ac DOT uk
CC: lslavoti AT mail DOT bcpl DOT net, djgpp AT delorie DOT com
Subject: Re: .EXE Size
References: <E0zQ05u-0003Qr-00 AT sable DOT ox DOT ac DOT uk>
Reply-To: djgpp AT delorie DOT com

George Foot wrote:
 
> Are you writing C++ programs with large static arrays?  If you
> do this then IIRC the whole array will be included in the
> executable, even if you don't initialise it.  Try allocating
> uninitialised arrays dynamically instead, and see if it helps.
> The other solution which you already discovered is to compress
> with DJP, which should remove all the dead space.
> 
> If you're using C then I don't think this matters.

If the array is at all initialized, it does.  For instance, this
example:

char huge[5000000] = "Tiny Initializer";

int main(void) { puts(huge); return 0; }

compiles to a 5 meg executable, most of which is zeros.  Perhaps you
have something similar.  Obviously, this can be written differently:

char *huge;

...
huge = malloc(5000000);
strcpy(huge, "Tiny Initializer");
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019