Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4522: allocation problem after grow
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-08-09 04:13:49
#4522: allocation problem after grow
-------------------------------+--------------------------------------------
Reporter: razzik@⦠| Owner: igaztanaga
Type: Bugs | Status: closed
Milestone: Boost 1.44.0 | Component: interprocess
Version: Boost 1.43.0 | Severity: Showstopper
Resolution: invalid | Keywords: interprocess shared_memory ipc grow allocation
-------------------------------+--------------------------------------------
Comment (by Raz M <razzik@â¦>):
'''Thanks igaztanaga!!'''[[br]]
You are right, in general the growing should be when the SM is unmapped.
Basically, I need shared memory with Fix memory size. But, I don't know
the memory size used by Shared Memory mechanism. So, I use grow after
using get_free_memory() function.
'''How can I set in the constructor of the managed_shared_memory the
required memory without knowing the SM mechanism size?'''
Thanks again for your assistance,[[br]]Raz
P.S.[[br]]General question:[[br]]If the SM based on file I can't call
shrink_to_fit() when the SM is mapped, But what about grow?
Replying to [comment:1 igaztanaga]:
> From the help:
>
> "Boost.Interprocess offers off-line segment growing. What does this
mean? That the segment can be grown if no process has mapped the managed
segment. If the application can find a moment where no process is attached
it can grow or shrink to fit the managed segment."
>
> So you must unmap, grow and remap it again:
>
> {{{#!c++
> /* Create SM - Size 100K*/<br>
> {
> managed_shared_memory shm(create_only, "MySM", 100*1024);
> }
> //Unmapped here
>
> /* Grow SM By 28K*/
> managed_shared_memory::grow("MySM",28*1024);
>
> //Remap it
> managed_shared_memory shm(open_only, "MySM");
>
> /* SM full size - 128K*/
> int fullSMSize = shm.get_size();
> /* SM mem size - 128K - sizeof(SM Header)*/
> int memSMSize = shm.get_free_memory();
> /* alloc 64K in SM (64K<128K)*/
> void* ptr = shm.allocate(64*1024);
> }}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/4522#comment:3> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC