Boost logo

Boost Users :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2007-11-08 13:32:44


Srinivas Gardas escribió:
> Hi,
> Is there any option to automatically increase the size of the 'Shared
> Memory' dynamically, in the shared memory objects of Interprocess
> library?
>
> Thanks & Regards,
> Srinivas Gardas

Automatically no. That would be nearly impossible to achieve because
every process attached to the segment would need to be notified, all of
them should remap it, and be successful. And all those steps should be
atomically executed.

The only option to grow shared memory/memory mapped files is to make
sure no processes are attached to it and call
"managed_shared_memory::grow()". You can minimize the size of the shared
memory/memory mapped file (when no process is using it) calling
"shrink_to_fit".

Something like:

//Warning: no process should be using this shared memory

//Increase shared memory size with extra 16K
managed_shared_memory::grow("shmem_name", 16*1024);

//Minimize the size of the shared memory
managed_shared_memory::shrink_to_fit("shmem_name");

//Now open it again with the new size
managed_shared_memory shm(open_only, "shmem");

These functions are experimental and they are not explained in the docs.
I will add them as official when I'm sure they are production ready. If
you want to test them and report if they are useful and correct, I would
be glad.

Regards,

Ion


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net