Boost C++ Libraries: Ticket #4522: allocation problem after grow https://svn.boost.org/trac10/ticket/4522 <p> Hi, </p> <p> the allocation mechanism damaged by call grow() function... </p> <p> This part work fine: </p> <p> <em>/* Create SM - Size 100K*/<br />managed_shared_memory shm(create_only, "MySM", 100*1024);<br />/* SM full size - 100K*/<br />int fullSMSize = shm.get_size();<br />/* SM mem size - 100K - sizeof(SM Header)*/<br />int memSMSize = shm.get_free_memory;<br />/* alloc 64K in SM (64K&lt;100K)*/<br />void* ptr = shm.allocate(64*1024);</em> </p> <p> By adding grow function the allocate function throws exception: </p> <p> <em>/* Create SM - Size 100K*/<br />managed_shared_memory shm(create_only, "MySM", 100*1024);<br /><strong>/* Grow SM By 28K*/<br />managed_shared_memory::grow("MySM",28*1024);<br /></strong>/* SM full size - 128K*/<br />int fullSMSize = shm.get_size();<br />/* SM mem size - 128K - sizeof(SM Header)*/<br />int memSMSize = shm.get_free_memory;<br />/* alloc 64K in SM (64K&lt;128K)*/<br />void* ptr = shm.allocate(64*1024);</em> </p> <p> Thanks, Raz </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4522 Trac 1.4.3 Ion Gaztañaga Sun, 08 Aug 2010 08:02:14 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4522#comment:1 https://svn.boost.org/trac10/ticket/4522#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> From the help: </p> <p> "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." </p> <p> So you must unmap, grow and remap it again: </p> <div class="wiki-code"><div class="code"><pre><span class="cm">/* Create SM - Size 100K*/</span><span class="o">&lt;</span><span class="n">br</span><span class="o">&gt;</span> <span class="p">{</span> <span class="n">managed_shared_memory</span> <span class="n">shm</span><span class="p">(</span><span class="n">create_only</span><span class="p">,</span> <span class="s">&quot;MySM&quot;</span><span class="p">,</span> <span class="mi">100</span><span class="o">*</span><span class="mi">1024</span><span class="p">);</span> <span class="p">}</span> <span class="c1">//Unmapped here</span> <span class="cm">/* Grow SM By 28K*/</span> <span class="n">managed_shared_memory</span><span class="o">::</span><span class="n">grow</span><span class="p">(</span><span class="s">&quot;MySM&quot;</span><span class="p">,</span><span class="mi">28</span><span class="o">*</span><span class="mi">1024</span><span class="p">);</span> <span class="c1">//Remap it</span> <span class="n">managed_shared_memory</span> <span class="nf">shm</span><span class="p">(</span><span class="n">open_only</span><span class="p">,</span> <span class="s">&quot;MySM&quot;</span><span class="p">);</span> <span class="cm">/* SM full size - 128K*/</span> <span class="kt">int</span> <span class="n">fullSMSize</span> <span class="o">=</span> <span class="n">shm</span><span class="p">.</span><span class="n">get_size</span><span class="p">();</span> <span class="cm">/* SM mem size - 128K - sizeof(SM Header)*/</span> <span class="kt">int</span> <span class="n">memSMSize</span> <span class="o">=</span> <span class="n">shm</span><span class="p">.</span><span class="n">get_free_memory</span><span class="p">();</span> <span class="cm">/* alloc 64K in SM (64K&lt;128K)*/</span> <span class="kt">void</span><span class="o">*</span> <span class="n">ptr</span> <span class="o">=</span> <span class="n">shm</span><span class="p">.</span><span class="n">allocate</span><span class="p">(</span><span class="mi">64</span><span class="o">*</span><span class="mi">1024</span><span class="p">);</span> </pre></div></div> Ticket Raz <razzik@…> Sun, 08 Aug 2010 11:12:26 GMT <link>https://svn.boost.org/trac10/ticket/4522#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4522#comment:2</guid> <description> <p> <strong>Thanks igaztanaga!''' </strong></p> <p> You are right, in general the growing should be when the SM is unmapped. </p> <p> 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 <em>get_free_memory()</em> function. </p> <p> <strong>How can I set in the constructor of the managed_shared_memory the required memory without knowing the SM mechanism size?</strong> </p> <p> Thanks again for your assistance,<br />Raz </p> <p> P.S. General question: If the SM based on file I can't call <em>shrink_to_fit()</em> when the SM is mapped, But what about grow? </p> </description> <category>Ticket</category> </item> <item> <author>Raz M <razzik@…></author> <pubDate>Mon, 09 Aug 2010 04:13:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4522#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4522#comment:3</guid> <description> <p> <strong>Thanks igaztanaga!'''<br /> </strong></p> <p> You are right, in general the growing should be when the SM is unmapped. </p> <p> 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. </p> <p> <strong>How can I set in the constructor of the managed_shared_memory the required memory without knowing the SM mechanism size?</strong> </p> <p> Thanks again for your assistance,<br />Raz </p> <p> 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? </p> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4522#comment:1" title="Comment 1">igaztanaga</a>: </p> <blockquote class="citation"> <p> From the help: </p> <p> "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." </p> <p> So you must unmap, grow and remap it again: </p> <div class="wiki-code"><div class="code"><pre><span class="cm">/* Create SM - Size 100K*/</span><span class="o">&lt;</span><span class="n">br</span><span class="o">&gt;</span> <span class="p">{</span> <span class="n">managed_shared_memory</span> <span class="n">shm</span><span class="p">(</span><span class="n">create_only</span><span class="p">,</span> <span class="s">&quot;MySM&quot;</span><span class="p">,</span> <span class="mi">100</span><span class="o">*</span><span class="mi">1024</span><span class="p">);</span> <span class="p">}</span> <span class="c1">//Unmapped here</span> <span class="cm">/* Grow SM By 28K*/</span> <span class="n">managed_shared_memory</span><span class="o">::</span><span class="n">grow</span><span class="p">(</span><span class="s">&quot;MySM&quot;</span><span class="p">,</span><span class="mi">28</span><span class="o">*</span><span class="mi">1024</span><span class="p">);</span> <span class="c1">//Remap it</span> <span class="n">managed_shared_memory</span> <span class="nf">shm</span><span class="p">(</span><span class="n">open_only</span><span class="p">,</span> <span class="s">&quot;MySM&quot;</span><span class="p">);</span> <span class="cm">/* SM full size - 128K*/</span> <span class="kt">int</span> <span class="n">fullSMSize</span> <span class="o">=</span> <span class="n">shm</span><span class="p">.</span><span class="n">get_size</span><span class="p">();</span> <span class="cm">/* SM mem size - 128K - sizeof(SM Header)*/</span> <span class="kt">int</span> <span class="n">memSMSize</span> <span class="o">=</span> <span class="n">shm</span><span class="p">.</span><span class="n">get_free_memory</span><span class="p">();</span> <span class="cm">/* alloc 64K in SM (64K&lt;128K)*/</span> <span class="kt">void</span><span class="o">*</span> <span class="n">ptr</span> <span class="o">=</span> <span class="n">shm</span><span class="p">.</span><span class="n">allocate</span><span class="p">(</span><span class="mi">64</span><span class="o">*</span><span class="mi">1024</span><span class="p">);</span> </pre></div></div></blockquote> </description> <category>Ticket</category> </item> </channel> </rss>