Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Jan 1998 20:07:31 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        joelh@gnu.org
Cc:        tlambert@primenet.com, chrisy@flix.net, freebsd-hackers@FreeBSD.ORG
Subject:   Re: sharable static arrays?
Message-ID:  <199801142007.NAA07464@usr06.primenet.com>
In-Reply-To: <199801140203.UAA03069@detlev.UUCP> from "Joel Ray Holveck" at Jan 13, 98 08:03:37 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> I *am* the original poster.  IIRC, a monitor common block is like an
> mmap'd block.  I just wanted a large const array across several
> simultanious invocations of a program to not take up lots of memory.
> That's all.

OK.  Sean was wrong and I was wrong.

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.

> > If you want to make a distinction between static and static global,
> > I still say you need a different section ID for the thing.
> 
> It's now unclear what you mean by 'static' vs. 'static global'.

All global data is static.  Not all static data is global.  Global
data with a "static" storage class is scoped locally to the .o file
in shich it was declared.  It's a scoping thing for:

int		i = 5;		/* statically initialized global data*/

static int	j = 4;		/* locally scoped statically inialized*/
				/* static global data*/

foo()
{
	static int	k = 4;	/* statically initialized static local data*/
	...
}

The distinction is important because if you agregate something, like
an array of structs, you can initialize it in any of these three types
of static, but not in an auto variable (you'll get the error "no auto
agregate initialization").

Anyway, "static global" data declared in more than one file is not
shared between declaration instances.  This tends to be a problem
mostly for C++ template classes with static components, where the
classes are instanced in more than one place.  This is because the
old tools that FreeBSD has fail to place template instances for a given
type in a seperate section so the linker can choose to have only one
copy lying around.

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-).


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199801142007.NAA07464>