Boost.MultiIndex:有没有办法在两个进程之间共享对象?

发布于 2024-08-28 04:45:09 字数 1459 浏览 5 评论 0原文

我有一个大约 10Gb 的 Boost.MultiIndex 大数组。为了减少读取,我认为应该有一种方法将数据保存在内存中,并且其他客户端程序将能够读取和分析它。

正确的组织方式是什么?

该数组看起来像:

    struct particleID
    {
    int           ID;// real ID for particle from Gadget2 file "ID" block
    unsigned int  IDf;// postition in the file
    particleID(int id,const unsigned int idf):ID(id),IDf(idf){}
    bool operator<(const particleID& p)const { return ID<p.ID;}
    unsigned int getByGID()const {return (ID&0x0FFF);};

    };

struct ID{};
struct IDf{};
struct IDg{};

typedef multi_index_container<
    particleID,
    indexed_by<
        ordered_unique<
            tag<IDf>,  BOOST_MULTI_INDEX_MEMBER(particleID,unsigned int,IDf)>,
        ordered_non_unique<
            tag<ID>,BOOST_MULTI_INDEX_MEMBER(particleID,int,ID)>,
        ordered_non_unique<
            tag<IDg>,BOOST_MULTI_INDEX_CONST_MEM_FUN(particleID,unsigned int,getByGID)> 
    >
> particlesID_set;

欢迎任何想法。

亲切的问候阿曼。

编辑: RAM 和核心数量不受限制。目前我有 16Gb 和 8 核。

更新

我在 Boost.Users 论坛中提出的同样的问题,我从 Joaquín M López Muñoz(Boost.MultiIndex 的开发者)那里得到了答案。答案是。可以使用 Boost.Interprocess 在进程之间共享 multi_index。有关更多详细信息,您可以参阅 此链接

I have a Boost.MultiIndex big array about 10Gb. In order to reduce the reading I thought there should be a way to keep the data in the memory and another client programs will be able to read and analyse it.

What is the proper way to organize it?

The array looks like:

    struct particleID
    {
    int           ID;// real ID for particle from Gadget2 file "ID" block
    unsigned int  IDf;// postition in the file
    particleID(int id,const unsigned int idf):ID(id),IDf(idf){}
    bool operator<(const particleID& p)const { return ID<p.ID;}
    unsigned int getByGID()const {return (ID&0x0FFF);};

    };

struct ID{};
struct IDf{};
struct IDg{};

typedef multi_index_container<
    particleID,
    indexed_by<
        ordered_unique<
            tag<IDf>,  BOOST_MULTI_INDEX_MEMBER(particleID,unsigned int,IDf)>,
        ordered_non_unique<
            tag<ID>,BOOST_MULTI_INDEX_MEMBER(particleID,int,ID)>,
        ordered_non_unique<
            tag<IDg>,BOOST_MULTI_INDEX_CONST_MEM_FUN(particleID,unsigned int,getByGID)> 
    >
> particlesID_set;

Any ideas are welcome.

kind regards Arman.

EDIT:
The RAM and the number of cores are not limited. Currently I have a 16Gb and 8cores.

Update

The same question I was asking in Boost.Users forum I got an answer from Joaquín M López Muñoz(developer of Boost.MultiIndex). The aswer is Yes. One can share the multi_index between processes using Boost.Interprocess. For more detail you can see in this link

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

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

发布评论

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

评论(2

凉月流沐 2024-09-04 04:45:09

您是否看过 Boost.Interprocess

Have you looked at Boost.Interprocess?

恏ㄋ傷疤忘ㄋ疼 2024-09-04 04:45:09

你有没有想过把它切成碎片。

并发访问很难。很难做到正确,很难维护,也很难推理。

另一方面,10GB 非常大,我想知道是否可以对数据进行集群。保持相同的 index 结构,但根据某些条件(例如大 ID)将其分派为 10 个(或更多)独立对象。

这样,您就可以自然地单独处理每个块,而无需首先处理并发访问。

Have you thought about cutting it into pieces.

Concurrent access is hard. Hard to get right, hard to maintain, hard to reason about.

On the other hand, 10GB is very big, and I wondered if you could cluster your data. Keep the same index structure but dispatch it into 10 (or more) independent objects depending on some conditions (the big id for example).

This way you could naturally process each chunk separately from the other without having to deal with concurrent access in the first place.

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