From owner-freebsd-hackers Wed Jan 14 23:16:02 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id XAA07347 for hackers-outgoing; Wed, 14 Jan 1998 23:16:02 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from wcc.wcc.net (wcc.wcc.net [208.6.232.10]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id XAA07220 for ; Wed, 14 Jan 1998 23:14:32 -0800 (PST) (envelope-from piquan@wcc.wcc.net) Received: from detlev.UUCP (newip29.wcc.net [206.104.247.29]) by wcc.wcc.net (8.8.7/8.8.7) with ESMTP id BAA11449; Thu, 15 Jan 1998 01:11:01 -0600 (CST) Received: (from joelh@localhost) by detlev.UUCP (8.8.8/8.8.7) id BAA04785; Thu, 15 Jan 1998 01:13:38 -0600 (CST) (envelope-from joelh) Date: Thu, 15 Jan 1998 01:13:38 -0600 (CST) Message-Id: <199801150713.BAA04785@detlev.UUCP> To: tlambert@primenet.com CC: tlambert@primenet.com, chrisy@flix.net, freebsd-hackers@FreeBSD.ORG In-reply-to: <199801142007.NAA07464@usr06.primenet.com> (message from Terry Lambert on Wed, 14 Jan 1998 20:07:31 +0000 (GMT)) Subject: Re: sharable static arrays? From: Joel Ray Holveck Reply-to: joelh@gnu.org References: <199801142007.NAA07464@usr06.primenet.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk > OK. Sean was wrong and I was wrong. Not wrong, if I understand properly, you just correctly answered a different question than what I meant to ask. > What you want is already in there. All original vnode data is > shared between all processes. This includes static data. The > program txt (executable code) is read-only. Data is read/write, but > is marked copy-on-write. You do not take memory space for > additional instances of the program, *unless* you write the data. > If you do, it's copied. A page at a time. Uninitialized and > allocated data are BSS data. This is allocated per process. So, let me make sure I've got this straight: int g_uninit; /* Global uninitialized */ int g_statinit = 1; /* Global statically initialized */ static int fs_g_uninit; /* File scope uninitialized */ static int fs_g_statinit = 1; /* File scope statically initialized */ const int g_const = 1; /* Global constant */ foo() { int local_uninit; /* Auto uninitialized */ int local_init = 4; /* Auto initialized */ static int ls_uninit; /* Local static uninitialized */ static int ls_init = 4; /* Local static initialized */ } Now, I know the scoping rules, and I know the lifetime-of-data rules. These are not my concern. If I understand right: g_statinit, fs_g_statinit, and ls_init are all stored in the data segment, which is allocated and initialized at compile-time, and at run-time is initially shared by all instances of the executable but is copy-on-write (per page). (I did not originally realize that the data segment was loaded copy-on-write; I had thought that a separate copy was generated for each process.) g_uninit, fs_g_uninit, and ls_uninit are all stored in the BSS segment. Memory is reserved in the virtual address space at load time, but not physically allocated until a page is written to during run-time. local_uninit and local_init are allocated on the stack at run-time. local_init is initialized at run-time (by code generated by the compiler) semimmediately after allocation. Now, my question originally boiled down to this: does g_const get allocated in text or data? I was assuming this would be significant because I thought that text was allocated as shareable, but data had a separate copy for each process. Now, realizing that data is copy-on-write, I discover it is not an issue. > I hope this answers all your questions, and the questions that the > initial answers might have raised, so we can put this to rest. 8-). All my questions raised by answers have been answered, and my original question has been shown to be moot. I, too, will tire of this thread before long. I do appreciate the help from all. Cheers, joelh -- Joel Ray Holveck - joelh@gnu.org - http://www.wp.com/piquan Fourth law of programming: Anything that can go wrong wi sendmail: segmentation violation - core dumped