Subject: [Boost-bugs] [Boost C++ Libraries] #4066: Boost::Interprocess::vector only pushes back so many correct values before it always pushes 0.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-04-05 06:31:38
#4066: Boost::Interprocess::vector only pushes back so many correct values before
it always pushes 0.
--------------------------------------+-------------------------------------
Reporter: powerking89670@⦠| Owner: igaztanaga
Type: Bugs | Status: new
Milestone: Boost 1.43.0 | Component: interprocess
Version: Boost 1.42.0 | Severity: Problem
Keywords: |
--------------------------------------+-------------------------------------
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.
{{{
#include <conio.h> //For getch
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/thread.hpp>
#include <stdio.h>
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<int, managed_shared_memory::segment_manager>
ShmemAllocator;
//Alias a vector that uses the previous STL-like allocator so that
allocates
//its values from the segment
typedef boost::interprocess::vector<int, ShmemAllocator> 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<MyVector>("MyVector")(alloc_inst);
myvector->reserve(5000);
for(int i = 0; i < 5000; i++) //Insert data in the vector
myvector->push_back(5);
for(unsigned int i=0; i < myvector->size(); i++)
{
printf("%u: %u\n", i+1, myvector[i]);
}
_getch();
return 0;
}
}}}
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.
Am I doing something incorrectly, or is this a problem with the lib?
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/4066> 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:02 UTC