[Newbie][Interprocess] Placing a boost interprocess vector in an existing (not managed) shared memory

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Newbie][Interprocess] Placing a boost interprocess vector in an existing (not managed) shared memory

Boost - Users mailing list

Hello Boost-Mailing-List,

 

I have a question about the boost interprocess library - and I hope I can explain it correctly.

 

I looked at the "Quick guide for the impatient" about the interprocess library - but I'm not sure if I can use this for our purpose.

The main goal is to insert a STL vector (or different container) in a predefined portion of an already existing shared memory. The main problem is, that we cannot use the managed_shared_memory code from boost, because we rely on a different API to allocate the shared memory between Windows and other devices. Also the container should be placed at a fixed offset inside the created shared memory.

 

I'm a complete newbie with boost and the interprocess library, that is why I'm not sure which interface I have to provide for the interprocess vector to be setup correctly. I hoped I could do something like:

 

new (srh_mem_base + offset) boost::interprocess::vector<allocator>;

 

I tried looking into the headers of the library to get an idea of that, but I honestly got lost.

 

I'm really sorry if this a stupid or obvious question - and I thank for any help in advance!

 

Kind greetings

Björn

Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [Newbie][Interprocess] Placing a boost interprocess vector in an existing (not managed) shared memory

Boost - Users mailing list
On 30/01/2020 9:19, Gaier, Bjoern via Boost-users wrote:

> Hello Boost-Mailing-List,
>
> I have a question about the boost interprocess library - and I hope I
> can explain it correctly.
>
> I looked at the "Quick guide for the impatient" about the interprocess
> library - but I'm not sure if I can use this for our purpose.
>
> The main goal is to insert a STL vector (or different container) in a
> predefined portion of an already existing shared memory. The main
> problem is, that we cannot use the managed_shared_memory code from
> boost, because we rely on a different API to allocate the shared memory
> between Windows and other devices. Also the container should be placed
> at a fixed offset inside the created shared memory.
>
> I'm a complete newbie with boost and the interprocess library, that is
> why I'm not sure which interface I have to provide for the interprocess
> vector to be setup correctly. I hoped I could do something like:
>
> new (srh_mem_base + offset) boost::interprocess::vector<allocator>;
>
> I tried looking into the headers of the library to get an idea of that,
> but I honestly got lost.
>
> I'm really sorry if this a stupid or obvious question - and I thank for
> any help in advance!

Unfortunatelly does not going to work. A shared memory vector expects a
shared memory allocator that relies on the segment_manager class. That
class expects a managed shared memory (or mapped file) that resolves
allocation requests looking for free space in the managed shared memory
segment.

You would need to define a new allocator and managed shared memory  (as
you need to handle the allocation requests from the vector) that
fulfills your needs. Not an easy task at all.

For fixed offsets, you'd better avoid Interprocess and use an array or
similar with no dynamic allocations.

Best,

Ion
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [Newbie][Interprocess] Placing a boost interprocess vector in an existing (not managed) shared memory

Boost - Users mailing list


On Thu, 13 Feb 2020 at 22:28, Ion Gaztañaga via Boost-users <[hidden email]> wrote:
On 30/01/2020 9:19, Gaier, Bjoern via Boost-users wrote:
> Hello Boost-Mailing-List,
>
> I have a question about the boost interprocess library - and I hope I
> can explain it correctly.
>
> I looked at the "Quick guide for the impatient" about the interprocess
> library - but I'm not sure if I can use this for our purpose.
>
> The main goal is to insert a STL vector (or different container) in a
> predefined portion of an already existing shared memory. The main
> problem is, that we cannot use the managed_shared_memory code from
> boost, because we rely on a different API to allocate the shared memory
> between Windows and other devices. Also the container should be placed
> at a fixed offset inside the created shared memory.
>
> I'm a complete newbie with boost and the interprocess library, that is
> why I'm not sure which interface I have to provide for the interprocess
> vector to be setup correctly. I hoped I could do something like:
>
> new (srh_mem_base + offset) boost::interprocess::vector<allocator>;
>
> I tried looking into the headers of the library to get an idea of that,
> but I honestly got lost.
>
> I'm really sorry if this a stupid or obvious question - and I thank for
> any help in advance!

Unfortunatelly does not going to work. A shared memory vector expects a
shared memory allocator that relies on the segment_manager class.

In the specific case of a vector, wouldn't it be simpler to allocate directly (a wrapper around VM) from Virtual Memory(i.e. without the segment manager, as there don't have to be segments, and there is nothing to manage), and there is nothing to relocate (ever, if you make the virtual reserved space adequately large)?

This is just an idea I've been thinking about (for my own purposes). What would be against this approach?

degski
 
That
class expects a managed shared memory (or mapped file) that resolves
allocation requests looking for free space in the managed shared memory
segment.

You would need to define a new allocator and managed shared memory  (as
you need to handle the allocation requests from the vector) that
fulfills your needs. Not an easy task at all.

For fixed offsets, you'd better avoid Interprocess and use an array or
similar with no dynamic allocations.

Best,

Ion
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users


--
@realdegski
"We value your privacy, click here!" Sod off! - degski
"Anyone who believes that exponential growth can go on forever in a finite world is either a madman or an economist" - Kenneth E. Boulding
"Growth for the sake of growth is the ideology of the cancer cell" - Edward P. Abbey

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [Newbie][Interprocess] Placing a boost interprocess vector in an existing (not managed) shared memory

Boost - Users mailing list

Hey degski,

 

sorry for the late reply. Things are kinda stressful here.

 

In general your idea is good – but in the future I wanted to replace the vector with a list. I just wanted to start easy and wondered if there is a generic solution.

 

Kind greetings

Björn

 

From: Boost-users <[hidden email]> On Behalf Of degski via Boost-users
Sent: 26 February 2020 13:56
To: Boost users list <[hidden email]>
Cc: degski <[hidden email]>
Subject: Re: [Boost-users] [Newbie][Interprocess] Placing a boost interprocess vector in an existing (not managed) shared memory

 

 

 

On Thu, 13 Feb 2020 at 22:28, Ion Gaztañaga via Boost-users <[hidden email]> wrote:

On 30/01/2020 9:19, Gaier, Bjoern via Boost-users wrote:
> Hello Boost-Mailing-List,
>
> I have a question about the boost interprocess library - and I hope I
> can explain it correctly.
>
> I looked at the "Quick guide for the impatient" about the interprocess
> library - but I'm not sure if I can use this for our purpose.
>
> The main goal is to insert a STL vector (or different container) in a
> predefined portion of an already existing shared memory. The main
> problem is, that we cannot use the managed_shared_memory code from
> boost, because we rely on a different API to allocate the shared memory
> between Windows and other devices. Also the container should be placed
> at a fixed offset inside the created shared memory.
>
> I'm a complete newbie with boost and the interprocess library, that is
> why I'm not sure which interface I have to provide for the interprocess
> vector to be setup correctly. I hoped I could do something like:
>
> new (srh_mem_base + offset) boost::interprocess::vector<allocator>;
>
> I tried looking into the headers of the library to get an idea of that,
> but I honestly got lost.
>
> I'm really sorry if this a stupid or obvious question - and I thank for
> any help in advance!

Unfortunatelly does not going to work. A shared memory vector expects a
shared memory allocator that relies on the segment_manager class.

 

In the specific case of a vector, wouldn't it be simpler to allocate directly (a wrapper around VM) from Virtual Memory(i.e. without the segment manager, as there don't have to be segments, and there is nothing to manage), and there is nothing to relocate (ever, if you make the virtual reserved space adequately large)?

 

This is just an idea I've been thinking about (for my own purposes). What would be against this approach?

 

degski

 

That
class expects a managed shared memory (or mapped file) that resolves
allocation requests looking for free space in the managed shared memory
segment.

You would need to define a new allocator and managed shared memory  (as
you need to handle the allocation requests from the vector) that
fulfills your needs. Not an easy task at all.

For fixed offsets, you'd better avoid Interprocess and use an array or
similar with no dynamic allocations.

Best,

Ion
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users



--

@realdegski

"We value your privacy, click here!" Sod off! - degski

"Anyone who believes that exponential growth can go on forever in a finite world is either a madman or an economist" - Kenneth E. Boulding

"Growth for the sake of growth is the ideology of the cancer cell" - Edward P. Abbey

Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users