From owner-freebsd-hackers Fri May 7 21:25:11 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from smtp2.vnet.net (smtp2.vnet.net [166.82.1.32]) by hub.freebsd.org (Postfix) with ESMTP id 2F70215618 for ; Fri, 7 May 1999 21:25:08 -0700 (PDT) (envelope-from rivers@dignus.com) Received: from dignus.com (ponds.vnet.net [166.82.177.48]) by smtp2.vnet.net (8.9.1a/8.9.1) with ESMTP id AAA08734; Sat, 8 May 1999 00:03:09 -0400 (EDT) Received: from lakes.dignus.com (lakes.dignus.com [10.0.0.3]) by dignus.com (8.9.2/8.8.5) with ESMTP id AAA13544; Sat, 8 May 1999 00:02:00 -0400 (EDT) Received: (from rivers@localhost) by lakes.dignus.com (8.9.2/8.6.9) id AAA01012; Sat, 8 May 1999 00:01:55 -0400 (EDT) Date: Sat, 8 May 1999 00:01:55 -0400 (EDT) From: Thomas David Rivers Message-Id: <199905080401.AAA01012@lakes.dignus.com> To: adam@whizkidtech.net, rivers@dignus.com Subject: Re: wc* routines Cc: dima@tejblum.dnttm.rssi.ru, freebsd-hackers@FreeBSD.ORG In-Reply-To: <19990507201101.A216@whizkidtech.net> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > 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