comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Johnson <mark_h_johnson@raytheon.com>
Subject: Re: Why is memory footprint smaller when compiled static?
Date: Tue, 04 Jun 2002 11:13:26 -0500
Date: 2002-06-04T11:13:26-05:00	[thread overview]
Message-ID: <3CFCE726.38B15035@raytheon.com> (raw)
In-Reply-To: slrnafpmag.47h.randhol+abuse@kiuk0156.chembio.ntnu.no

Preben Randhol wrote:
> [snip - static bigger on disk]
> When I run the two programs and examine the memory usage of the two
> programs I find :
> 
>    3296 kb for the static version
>    4412 kb for the dynamic version
> 
> Why is there such a big difference? Is it because the compiler can do
> better job at optimising the code when you build it statically.
> 
Hmm. I doubt the compiler (gcc) has anything to do with this. The linker
(ld) is the likely culprit and you should see two effects...
 - each static program has a "smaller footprint" because functions and
procedures in the library that are not used can be omitted from the
generated main program. However,...
 - your overall memory usage of the system can be higher when you run
several of these statically linked programs because they do not share
the run time library.
The second effect can be a pretty substantial by the way. I have seen
some systems implemented with a "server" and a separate main program for
each "display". With statically linked main programs, the memory usage
of the system is unacceptable when you get 5-10 displays up. With shared
libraries, the memory usage is OK. YMMV.

> I also did the same without the -O3 switch and then the memory usage
> was:
> 
>    3412 kb for the static version
>    4512 kb for the dynamic version
> 
It is somewhat interesting that the dynamic version went up by 100 kb
and the static version went up by 116 kb, but you might have just gotten
"lucky" with an extra segment or two going up by a 4k page in the static
version. Check the link map (something like - gnatmake ... -largs
-Wl,-Map,glosa.map) if you want to get more insight in how the linker is
putting the application together.
  --Mark



  reply	other threads:[~2002-06-04 16:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-04 15:14 Why is memory footprint smaller when compiled static? Preben Randhol
2002-06-04 16:13 ` Mark Johnson [this message]
2002-06-04 21:01 ` Florian Weimer
2002-06-04 21:02 ` Florian Weimer
2002-06-04 21:03 ` Florian Weimer
2002-06-05 11:10   ` Preben Randhol
  -- strict thread matches above, loose matches on Subject: below --
2002-06-05 11:37 Grein, Christoph
2002-06-05 12:36 ` Preben Randhol
2002-06-05 13:42   ` Mark Johnson
2002-06-06  0:02   ` Steven Deller
2002-06-06 10:35     ` Preben Randhol
2002-06-06 14:26     ` Gautier
2002-06-06 15:08       ` Jean-Marc Bourguet
2002-06-06 15:24         ` Jean-Pierre Rosen
2002-06-06 19:35           ` Jeffrey Carter
2002-06-10 23:51     ` Randy Brukardt
2002-06-11  0:53       ` Robert A Duff
2002-06-11 16:45         ` Wes Groleau
2002-06-11 17:08           ` Preben Randhol
2002-06-11 19:12             ` Wes Groleau
2002-06-11 21:38               ` Randy Brukardt
2002-06-11 21:32         ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox