zoukankan      html  css  js  c++  java
  • C++: Virtual Table and Shared Memory

    See at:

    补充栏3: C++对象和共享内存 (叙述内容和Link1的内容基本一致)

    《C++网络编程 卷1:运用ACE和模式消除复杂性》 《C++ Network Programming Volume 1 Mastering Complexity with ACE and Patterns》 -Douglas C.Schmidt, Stephen D. Huston -叶斌译

     关于这个问题的一个扩展: p49, class ACE_IPC_SAP的constructor为protected, 这样可以防止其被直接实例化,同时避免了虚指针。

     关于这个问题的另一个扩展:  p106, 在多线程情况下,可以使用含有虚表的C++对象,利用进程局部内存的公用数据结构。

    Link1:

    Is it possible to store polymorphic class in shared memory? -> No

    http://stackoverflow.com/questions/12969391/is-it-possible-to-store-polymorphic-class-in-shared-memory

    引自

    http://www.boost.org/doc/libs/1_51_0/doc/html/interprocess/sharedmemorybetweenprocesses.html#interprocess.sharedmemorybetweenprocesses.mapped_region_object_limitations

    Virtuality forbidden

    The virtual table pointer and the virtual table are in the address space of the process that constructs the object, so if we place a class with a virtual function or virtual base class, the virtual pointer placed in shared memory will be invalid for other processes and they will crash.

    This problem is very difficult to solve, since each process needs a different virtual table pointer and the object that contains that pointer is shared across many processes. Even if we map the mapped region in the same address in every process, the virtual table can be in a different address in every process. To enable virtual functions for objects shared between processes, deep compiler changes are needed and virtual functions would suffer a performance hit. That's why Boost.Interprocess does not have any plan to support virtual function and virtual inheritance in mapped regions shared between processes.

    ..

  • 相关阅读:
    LeetCode题解之Flipping an Image
    LeetCode 之Find Minimum in Rotated Sorted Array
    LeetCode题解Transpose Matrix
    LeetCode 题解之Minimum Index Sum of Two Lists
    LeetCode题解之Intersection of Two Linked Lists
    LeetCode 题解之Add Two Numbers II
    LeetCode题解之Add two numbers
    href="#"与href="javascript:void(0)"的区别
    有关ie9 以下不支持placeholder属性以及获得焦点placeholder的移除
    ie7下属性书写不规范造成的easyui 弹窗布局紊乱
  • 原文地址:https://www.cnblogs.com/hellohelloworld/p/5634280.html
Copyright © 2011-2022 走看看