Boost C++ Libraries: Ticket #4066: Boost::Interprocess::vector only pushes back so many correct values before it always pushes 0. https://svn.boost.org/trac10/ticket/4066 <p> I was perusing the documentation on interprocess, and I decided to scale up the example a bit to make sure it would suit my purposes. </p> <pre class="wiki">#include &lt;conio.h&gt; //For getch #include &lt;boost/interprocess/managed_shared_memory.hpp&gt; #include &lt;boost/interprocess/containers/vector.hpp&gt; #include &lt;boost/interprocess/allocators/allocator.hpp&gt; #include &lt;boost/thread.hpp&gt; #include &lt;stdio.h&gt; using namespace boost::interprocess; //Define an STL compatible allocator of ints that allocates from the managed_shared_memory. //This allocator will allow placing containers in the segment typedef allocator&lt;int, managed_shared_memory::segment_manager&gt; ShmemAllocator; //Alias a vector that uses the previous STL-like allocator so that allocates //its values from the segment typedef boost::interprocess::vector&lt;int, ShmemAllocator&gt; MyVector; int main(int argc, char* argv[]) { struct shm_remove { shm_remove() { shared_memory_object::remove("MySharedMemory"); } ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); } } remover; //Create a new segment with given name and size managed_shared_memory segment(create_only, "MySharedMemory", 80000); //Initialize shared memory STL-compatible allocator const ShmemAllocator alloc_inst (segment.get_segment_manager()); //Construct a vector named "MyVector" in shared memory with argument alloc_inst MyVector *myvector = segment.construct&lt;MyVector&gt;("MyVector")(alloc_inst); myvector-&gt;reserve(5000); for(int i = 0; i &lt; 5000; i++) //Insert data in the vector myvector-&gt;push_back(5); for(unsigned int i=0; i &lt; myvector-&gt;size(); i++) { printf("%u: %u\n", i+1, myvector[i]); } _getch(); return 0; } </pre><p> However, when this code is build/run it outputs the correct value for a while and then suddenly the values switch to 0 or vary widely. </p> <p> Am I doing something incorrectly, or is this a problem with the lib? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4066 Trac 1.4.3 joseph.h.garvin@… Mon, 05 Apr 2010 22:24:34 GMT <link>https://svn.boost.org/trac10/ticket/4066#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4066#comment:1</guid> <description> <p> In the printf you should be passing (*myvector)[i], not myvector[i]. With that change compiles and runs fine for me printing 5 the whole time on Solaris. </p> </description> <category>Ticket</category> </item> <item> <author>powerking89670@…</author> <pubDate>Tue, 06 Apr 2010 01:07:02 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4066#comment:2 https://svn.boost.org/trac10/ticket/4066#comment:2 <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> That solved the issue. I had thought I tried everything. I guess not! </p> <p> Thank you very much! </p> Ticket