Boost::与复杂的嵌套类进行交互

发布于 2024-09-14 06:03:20 字数 1343 浏览 0 评论 0原文

我想我终于掌握了 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 库结构了。

帮助!

I think I finally have a grasp on the basics of the boost:interprocess library, and I've been using it successfully when dealing with relatively simple classes that contain a few member variables that are all standard data types.

However, I am now faced with the problem of pushing a rather complex class out into interprocess shared memory and I'm having no luck at all. I'm hoping someone here can help (or can steer me towards an alternate solution). Stripping it down to what I hope are the basics, I have something along these lines:

// 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;
}

What I need to do is create a vector of SharedClass objects in the interprocess memory space so that multiple processes can access the data. No matter what I try, I cannot seem to find a solution. It seems like there should be an easier way than making every single member variable along the way an interprocess version (interprocess::vector, interprocess::string, offset_ptr, etc), but maybe not. And even then, I'm not sure how to deal with all the allocators and such, not to mention the GSL library structures.

Help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゝ偶尔ゞ 2024-09-21 06:03:20

你的问题是STL容器。正如您所猜测的,您需要使用 boost::interprocess 容器。

例如,有关使用字符串的信息,请参阅我的回答
对于向量,请参阅这个< /a>.

干杯

You problem is with STL containers. As you've guessed, you need to use the boost::interprocess containers.

For example on using strings, see my answer here.
For vector, see this.

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文