From owner-freebsd-questions Wed May 17 1:43:18 2000 Delivered-To: freebsd-questions@freebsd.org Received: from dire.bris.ac.uk (dire.bris.ac.uk [137.222.10.60]) by hub.freebsd.org (Postfix) with ESMTP id 204EA37BAFE for ; Wed, 17 May 2000 01:43:15 -0700 (PDT) (envelope-from Jan.Grant@bristol.ac.uk) Received: from mail.ilrt.bris.ac.uk by dire.bris.ac.uk with SMTP-PRIV with ESMTP; Wed, 17 May 2000 09:43:08 +0100 Received: from localhost (cmjg@localhost) by mail.ilrt.bris.ac.uk (8.8.7/8.8.8) with ESMTP id JAA01896; Wed, 17 May 2000 09:43:07 +0100 (BST) Date: Wed, 17 May 2000 09:43:07 +0100 (BST) From: Jan Grant To: Gustavo Vieira Goncalves Coelho Rios Cc: freebsd-questions@freebsd.org Subject: Re: what's the advantage... In-Reply-To: <39214A8F.FC9C023E@tdnet.com.br> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 16 May 2000, Gustavo Vieira Goncalves Coelho Rios wrote: > > On Tue, 16 May 2000, Gustavo Vieira Goncalves Coelho Rios wrote: > > > > > I got surprised when i compiled two versions of the same program, and > > > the one statically (-static flag) linked use less memory than that > > > dynamically linked. > > Programs linked with the -static flag use less memory than that ones not > linked with -static flag. > Why ? > > > > How can one program that were static linked uses less memory that the > > > same one done using the default linking? > > > > I'd suspect that any (small) differences you're seeing could be > > attributed to mmapped .so files needing to be aligned with page > > boundaries. > > How could i do that ? > > So, try this simple program and use ps or top to see the difference > between them both. I tried it, and I see what you mean. If you get lsof to look at the processes, however, you'll see where the difference lies. With a statically-linked program, only the library functions it needs (those it uses and their dependencies) are linked in; the size of the executable is pretty much the total text usage of the program. With a dynamically-linked program, the libc.so is mmapped in en bloc; there's no way of avoiding this, and it counts towards the total size of the program. However, in theory the text of .so libraries can be shared between processes, thus cutting down on the total average overhead. I've no idea if FreeBSD implements that sharing - anyone care to comment? -- jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/ Tel +44(0)117 9287163 Fax +44 (0)117 9287112 RFC822 jan.grant@bris.ac.uk Axioms speak louder than words. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message