Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2007-03-10 15:22:42

Vishnu M Menon wrote:
>> You might like to have a look at this thread where I
>> asked the GNU libstdc++ people about this:
> Thanks for the reply.
> I was just wondering: my problem will be solved if I
> can ensure that the shared memory is mapped to the
> same virtual memory address range in all processes
> that access it.
> Do you know of any way this can be done in Linux and
> Solaris? I have full control of how the programs will
> be compiled and linked, if any change at that level is
> necessary. It may not be the most general solution,
> but it'll work in my case.

UNIX mmap offers the way to map a shared memory segment at a fixed
address. Boost.Interprocess also offers this possibility. You can use
fixed_managed_shared_memory class to create a shared memory segment with
object construction capabilities (just like managed_shared_memory),
whose allocators will define pointer like a raw pointer, and that can be
mapped at a fixed address.

Take this example:

tiny url:

and change it replacing:

managed_shared_memory --> fixed_managed_shared_memory

boost::interprocess containers --> stl containers

The line

managed_shared_memory shm(create_only, "myshm", 10000);


fixed_managed_shared_memory shm(create_only, "myshm", 10000,
        --> /*mapping address*/);

With these changes you will be able to use boost.interprocess allocators
with stl containers and map all in a fixed address in all processes.

I think this should be added as a new chapter in the next Interprocess

I hope this helps,


Boost list run by bdawes at, gregod at, cpdaniel at, john at