【问题标题】:Boost::Interprocess with complex, nested classesBoost::Interprocess 与复杂的嵌套类
【发布时间】:2010-08-11 15:16:04
【问题描述】:

我想我终于掌握了 boost:interprocess 库的基础知识,并且在处理包含一些成员变量的相对简单的类时,我已经成功地使用了它,这些成员变量都是标准数据类型。

但是,我现在面临将一个相当复杂的类推到进程间共享内存中的问题,而且我一点运气都没有。我希望这里有人可以提供帮助(或者可以引导我寻求替代解决方案)。将其剥离为我希望的基础知识,我有以下几点:

// these first two classes are from the Gnu Scientific Library, so I can't  
// (or won't) be able to mess with the definition of these structures.  
typedef struct   
{  
    size_t size1;  
    size_t size2;  
    size_t tda;  
    double * data;  
    gsl_block * block;  
    int owner;  
} gsl_matrix;  

typedef struct   
{
    size_t size1;
    size_t size2;
    size_t tda;
    int * data;
    gsl_block_int * block;
    int owner;
} gsl_matrix_int;

class MyNumbersClass
{
    gsl_matrix_int* m_pIntMatrix;
    gsl_matrix*     m_pDblMatrix;
    unsigned int iVal1;
    unsigned int iVal2;
}

class MyOtherDataClass
{
    std::vector<int> m_vInputs;
    std::vector<double> m_vOutputs;
    std::string m_sTitle;
    bool m_bCorrect;
}

class SharedClass
{
    MyNumbersClass* m_pFirstNumbers;
    std::vector<double> m_vDblData;
    std::vector<MyOtherDataClass> m_vOtherData;
}

我需要做的是在进程间内存空间中创建一个 SharedClass 对象的向量,以便多个进程可以访问数据。无论我尝试什么,我似乎都找不到解决方案。似乎应该有一种更简单的方法,而不是让每个成员变量沿途成为进程间版本(interprocess::vector、interprocess::string、offset_ptr 等),但也许不是。即便如此,我也不确定如何处理所有分配器等,更不用说 GSL 库结构了。

救命!

【问题讨论】:

    标签: c++ boost-interprocess


    【解决方案1】:

    您的问题在于 STL 容器。如您所料,您需要使用 boost::interprocess 容器。

    有关使用字符串的示例,请参阅my answer here。 向量见this

    干杯

    【讨论】:

      猜你喜欢
      • 2011-09-17
      • 2012-09-06
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      • 2011-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多