在C ++中的进程之间共享CGAL的几何 [英] Share CGAL's geometry between processes in C++

查看:264
本文介绍了在C ++中的进程之间共享CGAL的几何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在进程(C ++)之间发送CGAL几何的最快方法。假设我们有2个进程 - A和B.进程A生成几何,进程B显示它。我想以最快的可用方式连接它们。几何是CGALs多面体类型。

I'm looking for the fastest way to send CGAL's geometry between processes (C++). Lets assume, that we have 2 processes - A and B. Process A is generating geometry and process B is displaying it. I want to connect them in the fastest awailable way. The geometry is of CGALs Polyhedron type.

我知道我可以使用共享内存,但是我有一些问题:

I know I can use shared memory, but then I've got some problems:


  1. 当我想将几何从进程A复制到共享内存时,我可以使用流式多面体从/到OFF格式,但我不感兴趣,因为转换为这种格式是

  2. 我可以创建共享内存并使用placement new在共享内存中创建我的对象,并克服流和转换的开销,但是我没有进一步通过内部多面体函数控制内存分配。 (例如,当使用Polyhedron_incremental_builder_3添加新顶点时,我不能指定应该放在内存中的什么位置 - 我可以调用B.add_vertex(Point(0,0,0));并且在该方法中处理内存分配内部)

有没有办法在共享内存中的特定位置创建对象,并确保它及其动态结构将活在这个记忆?

Is there any way to create object in a specific place in shared memory and ensure, that it and its dynamic structures will "live" in this memory?

或者也许有另一种快速的方式在两个进程之间共享动态数据(即Halfedge结构)?

Or maybe there’s another fast way of sharing dynamic data (ie. Halfedge structures) between two processes?

推荐答案


我没有进一步控制内部多边形
函数的内存分配。

I have no further control of memory allocation by internal Polyhedron functions.

您实际上有控制权。

参考手册说:


类Polygon_2实现多边形。
Polygon_2由traits
类和容器类参数化。后者可以是满足
STL容器的要求的任何类。它默认为向量
类。

The class Polygon_2 implements polygons. The Polygon_2 is parameterized by a traits class and a container class. The latter can be any class that fulfills the requirements for an STL container. It defaults to the vector class.

除了本身,你需要一个容器,你可以放在共享内存。您可以尝试使用 boost :: interprocess :: vector ,或者滚动您自己的容器类。

In addition to using placement new for the polygon itself, you need a container that you can place in the shared memory. You can try to use boost::interprocess::vector, or roll your own container class.

使用 boost :: interprocess :: vector ,你需要为它创建一个包装类,因为与STL容器不同,它的构造函数需要一个分配器 object Polygon_2 将无法正确构建它。所以你必须从某种全局变量获取共享内存分配器对象。例如:

If you use boost::interprocess::vector, you will need to create a wrapper class for it, because unlike an STL container, its constructor requires an allocator object. Polygon_2 will not be able to construct it correctly. So you will have to get your shared memory allocator object from some kind of global variable. For example:

using namespace boost::interprocess;
typedef allocator<int, managed_shared_memory::segment_manager>  ShmemAllocator;
ShmemAllocator some_global_shmem_allocator;
template <typename T>
class my_shared_memory_vector : vector<T, ShmemAllocator>
{
public:
  my_shared_memory_vector() : vector(some_global_shmem_allocator) {}
};

免责声明:我自己没有做任何这些。如果你的电脑因为这样做而引起火焰,你的房子会烧坏,不要让我负责。通过仔细检查(通过查看GCAL源)任何内存 Polygon_2 分配实际上由容器管理是明智的。

Disclaimer: I have not actually done any of this myself. If your computer catches flame as a result of doing this and your house burns down, don't hold me responsible. It would be wise to double-check (by looking at the GCAL source) that any memory Polygon_2 allocates is actually managed by the container.

编辑:我误读了这个问题,它询问了多面体,而不是多边形。请参阅下面的注释。

Edit: I have misread the question, it asks about Polyhedra, not Polygons. See comment below.

这篇关于在C ++中的进程之间共享CGAL的几何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆