Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 May 1999 00:01:55 -0400 (EDT)
From:      Thomas David Rivers <rivers@dignus.com>
To:        adam@whizkidtech.net, rivers@dignus.com
Cc:        dima@tejblum.dnttm.rssi.ru, freebsd-hackers@FreeBSD.ORG
Subject:   Re: wc* routines
Message-ID:  <199905080401.AAA01012@lakes.dignus.com>
In-Reply-To: <19990507201101.A216@whizkidtech.net>

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> Hmmmm.... Isn't the C library linked dynamically? I was under the impression
> that if you update the library, all C programs are automatically going to
> use it. Isn't that correct?

 Actually - it's up to the program developers - they can deliver their
 program linked either statically, or dynamically.

 Several years ago; I used to be a big advocate for linking with dynamic
 libraries... but, trying to maintain an old version of a program on
 progressively new releases of the library became too much of a headache.
 (things aren't _supposed_ to break when you put that new library on,
 but, they do... and more frequently than I care for.)

 So - now, I'm an advocate of statically linked programs.

 Disk space and memory aren't very big concerns for me anymore.

 As far as the potential load time improvements - well, the maintanence
 burden just got too big to support it.


> 
> Now to the big question (since I am still relatively new to FreeBSD): Suppose
> several programs running at the same time want to use the wctype functions.
> Since there is only one Unicode/ISO 10646, they all need to use the exact
> same data loaded from the exact same file. This data, once loaded, is read only.
> 
> Is there a way for all programs to share the same data? I mean, I will have
> a pointer, _wct, which initially is NULL. Once any of the wctype functions is
> called for the first time, the library will check for the existence of that
> file. If it does not find it, it will use the reasonable subset.

 You can use shared memory... but, honestly, I don't think it will be
 a big issue...   I mean, it's 3000 characters, give or take, which is
 6000 bytes (maybe 12000 if you have a 4-byte character code) - this
 really isn't enough to bother with.

> 
> However, if it does find the file, it will allocate memory and read the file
> to it. This is where I would like the _wct pointer and the memory allocated
> to it shared by all programs.
> 
> By the same token, I need to know how many programs are using it, so when a
> program exits, it only frees the memory if it is the last of the programs
> using it.
> 
> In other words, is there a way to allocate memory shared by several programs,
> and is there a way to declare that certain specific variables (e.g. the
> _wcs pointer) be shared by all programs?
> 
> And if it is possible (I sure hope so, because it would be a major waste of
> memory to have to read the same file separately for each program), is there
> a way to change the memory, once allocated and filled, to read only, so if
> some wild pointer tries to overwrite it, it will not be able to do it?
> 
> I know this sounds like a somewhat naive question, but, as I said, I am still
> not fully familiar with the inner workings of FreeBSD. I am assuming the answer
> to all these questions is yes, and what I really need to know is how to do it.
> 
> Adam
> 

 All these questions are answered "yep - I think so" - by using
 shared memory.

 However, I'd add that:
	1)  I don't believe the complications that brings are
            worth the savings

	2)  It will keep me from using the library in other (non-UNIX)
	    contexts, which would be disappointing.

	3)  You are not guaranteed that a FreeBSD kernel has been
	    compiled with shared memory enabled, so you'd need to
	    "fall back" to allocating them separately anyway.


You goal of minimizing space is laudable... perhaps the file could
be broken up so that each program only read the code it needed, instead
of everyone reading the entire file?

As far as "finding the file" - I suggest you look at how the locale
library does this (in fact, I suggest you simply "steal" much of this
from there) - basically, define a location in /usr/include/paths.h.
Look there for the file...  if it's not there - well, you didn't
find it.


	- Dave Rivers -


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




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