From owner-freebsd-hackers Thu Jan 15 18:55:05 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id SAA14782 for hackers-outgoing; Thu, 15 Jan 1998 18:55:05 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from bcarsde4.nortel.ca (mailgate.nortel.ca [192.58.194.74]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id SAA14699 for ; Thu, 15 Jan 1998 18:54:22 -0800 (PST) (envelope-from atrens@nortel.ca) Message-Id: <199801160254.SAA14699@hub.freebsd.org> Received: from bcarsfbb.ca.nortel.com by bcarsde4.nortel.ca; Thu, 15 Jan 1998 21:50:14 -0500 Received: from ca.nortel.com by bcarsfbb.ca.nortel.com id <01767-0@bcarsfbb.ca.nortel.com>; Thu, 15 Jan 1998 21:49:28 -0500 Date: 15 Jan 1998 21:03 EST To: joelh@gnu.org, hackers@FreeBSD.ORG From: "Andrew Atrens" Subject: Re: sharable static arrays? Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk >Hmmmm.... Either way, it's illegal to define 'foobared' twice. Sorry, bad example. >If these were auto variables, then strategy a would require both stack >space for the array at runtime, and text space for the initial value >in the executable, whereas strategy b should only require one copy of >its space in either text or data, I still haven't determined which. The initializer on the right of the `=' is *always* a const. and gets stored in the text segment. Fortunately, if you make the thing on the left of the `=' a const most compilers will not duplicate the store. Therefore, const char foob[10] = "0123456789"; will use 10 bytes ( all in text ) , and char fooba[10] = "0123456789"; will use 20 bytes ( ten in text, ten in data ). It's that simple. ;) Now, what's interesting is that char foobar[10] = " "; will *also* use 20 bytes - the compiler will pad the initializer with zeroes. So if you have a big dataset, make it const. You'll only get one copy (which is all you really want) and it'll be in a shareable text segment :) Andrew