Date: Thu, 15 Jan 1998 01:13:38 -0600 (CST) From: Joel Ray Holveck <joelh@gnu.org> To: tlambert@primenet.com Cc: tlambert@primenet.com, chrisy@flix.net, freebsd-hackers@FreeBSD.ORG Subject: Re: sharable static arrays? Message-ID: <199801150713.BAA04785@detlev.UUCP> In-Reply-To: <199801142007.NAA07464@usr06.primenet.com> (message from Terry Lambert on Wed, 14 Jan 1998 20:07:31 %2B0000 (GMT)) References: <199801142007.NAA07464@usr06.primenet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199801150713.BAA04785>