From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,79b248c1cf206957 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-04 09:15:09 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!newsfeed.sjc.globix.net!cyclone-sf.pbi.net!151.164.30.35!cyclone.swbell.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3CFCE726.38B15035@raytheon.com> From: Mark Johnson X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Why is memory footprint smaller when compiled static? References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 04 Jun 2002 11:13:26 -0500 NNTP-Posting-Host: 192.27.48.39 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 1023207269 192.27.48.39 (Tue, 04 Jun 2002 11:14:29 CDT) NNTP-Posting-Date: Tue, 04 Jun 2002 11:14:29 CDT Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:25310 Date: 2002-06-04T11:13:26-05:00 List-Id: 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