home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15830 < prev    next >
Encoding:
Text File  |  1992-11-05  |  3.4 KB  |  106 lines

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!spool.mu.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!agate!doc.ic.ac.uk!uknet!mcsun!sunic!seunet!enea!ermes!eny
  2. From: eny@ermes.enea.se (Erik Nykvist)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Linked Lists in Shared Memory:
  5. Message-ID: <1992Nov5.090303.17760@ermes.enea.se>
  6. Date: 5 Nov 92 09:03:03 GMT
  7. References: <1992Nov2.195623.20262@lsil.com>
  8. Organization: Project ERMES, Teli Telecom Sweden
  9. Lines: 95
  10.  
  11. ameesh@lsil.com (Ameesh Desai) writes:
  12. > In article 8463@BofA.com, karl@BofA.COM (Karl Nicholas) writes:
  13. > >
  14. > >    Greetings Netters:
  15. > >
  16. > >    I would like to build a linked list in 
  17. > >shared or global memory. 
  18. > *** BEWARE of the virtual table pointers ***
  19. > When sharing data, what you must take care of is that nothing in the shared memory
  20. > points to a local processes address space. You can easily take care of this by
  21. > allocating everything from shared memory using say an overloaded new operator.
  22. > What you do not control is the virtual table pointers generated by cfront
  23. > that will point into the local address space of the process that allocates the
  24. > object (calling the ctor).
  25. > Simple Solution:
  26. > Do not use virtual functions in objects that you want to share !
  27. >     This is very limiting. You can use some form of indirection to create
  28. >     your own version of virtual function implementation, but this will not 
  29. >     be as clean as the one provided by C++.
  30. > There could be other solutions such as, allow only one process to map the 
  31. > pages and fix the vtable pointers for that process. This could be slow !
  32. > Ask some ODBMS vendors ... they seemed to have solved this problem in some
  33. > manner. I suspect that they do not actually 'share' the *same* pages accross
  34. > processes. They must map them to different swap pages and fix the vtable ptrs.
  35. > Ameesh
  36. > ---
  37. > ______________________________     o__            
  38. > | _   /|     Ameesh Desai     \    ,>/_                              
  39. > | \`O.o'     LSI Logic Corp.   \__(_)`(_)_              email: ameesh@lsil.com
  40. > | =(_|_)=    MS E192, 1501 McCarthy Blvd. \             fax  : (408) 433-6802
  41. > |____U_______Milpitas, CA 95035____________\____________voice: (408) 433-4097 
  42.  
  43. I have used a technique based on the new-operator with placement-syntax.
  44. If we have objects that can only be accessed by one process at the time it
  45. is possible to adjust the this-pointer using this operator.
  46.  
  47. As long as the constructor used doesn't mutate the data members the affect of
  48. using this operator is only adjustment of the vtbl-pointer.
  49.  
  50. Example:
  51.  
  52. enum eIN_SHARED_MEMORY { IN_SHARED_MEMORY };
  53.  
  54. // I am not sure if you can overload based on enum:s yet
  55. // Assume there is a base class that provides a locking 
  56. // mechanism.
  57. class Shared : public Shared_Object
  58. {
  59. public:
  60.   Shared(eIN_SHARED_MEMORY) {}
  61.   Shared() : i(12) {}
  62.   virtual void foo();
  63.   void set(int);
  64. private:
  65.   int i;
  66. };
  67.  
  68. void
  69. Shared::foo()
  70. {
  71.    return i;
  72. }
  73.  
  74. // We also use the placement syntax to allocate the shared object.
  75. =========
  76. PROCESS 1
  77. =========
  78. {
  79.     Shared* sp = new (shared_mem) Shared;
  80.     Lock lock(*sp);
  81.     // Adjust vtbl
  82.     new (shared_mem) Shared(IN_SHARED_MEMORY);
  83.     sp->set(12);
  84.     cout << sp->foo() ,, endl;
  85.     ....
  86. }
  87.  
  88. I wonder if this technique can be of any practical use. I am not sure because
  89. my expericene in this field is only limited.
  90.  
  91. There are many problems to solve, inheritance, ... etc
  92.  
  93. Erik Nyquist, ENEA DATA AB,     erny@enea.se
  94.                 eny@ermes.enea.se
  95.