Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!mcvax!ukc!dcl-cs!aber-cs!pcg From: pcg@aber-cs.UUCP (Piercarlo Grandi) Newsgroups: comp.lang.c++ Subject: Re: Objects and Shared Memory Summary: C lacks relative pointers, or, shared memory is a bad thing Message-ID: <807@aber-cs.UUCP> Date: 10 Apr 89 12:13:19 GMT Reply-To: pcg@cs.aber.ac.uk (Piercarlo Grandi) Distribution: eunet,world Organization: Dept of CS, UCW Aberystwyth (Disclaimer: my statements are purely personal) Lines: 53 In article <5462@cbnews.ATT.COM> trm@cbnews.ATT.COM (Tom R. Mueller) writes: .... Given this answer and assuming that it isn't possible to cause the shared memory to be mapped to the same virtual address in every process, there are some more problems. Shared objects cannot have ordinary pointers inside them. Shared objects cannot have virtual member functions because they are implemented with pointers to functions. Frankly I do not see any problem with C++, or object orientedness. There are two solutions to your problem, and both do not involve C++ or object oriented design: RELATIVE POINTERS This is an extremely powerful and useful concept, and is missing from C. It is very useful to handle structures that may be present at different addresses at different times. What one wants is to define all pointers in a segment as relative to that segment. Relative pointers solve neatly also two other problems; segmented architectures (where they are definitely more general and subsume near pointers) and saving/restoring data to/from persistent storage, which is usually done instead by a clumsy process of linearization. Note that this usual alternative is essentially transforming on save all pointers to relative pointers, and then on reload transforming them back to absolute ones. Relative pointers may be defined in at least three ways (e.g. segmented, based ala PL/1, relative ala MUPL). I am uncertain as to which I prefer. Probably the segmented variety is what would serve you best. In it a pointer declared as relative when dereferenced has the segment number of ITS address prepended to it automatically. NO SHARED MEMORY I reckon that shared memory is absolutely unnecessary, just like message passing. I have designed and am building an OS nucleus (in C++) that will have neither; address spaces are going to be persistent, and threads will be able to jump from one to another. In this way when two threads communicate they are always in the same address space, and no portion of address or data space is ever shared (which means that the address space can be on different machines). By the way, I am also considering adding relative pointers (or based ones) to C++ as well (to make save/restore easier, not because of sharing). -- Piercarlo "Peter" Grandi | ARPA: pcg%cs.aber.ac.uk@nss.cs.ucl.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcvax!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk