|
Boost : |
Subject: [boost] boost::interprocess::bad_alloc in copy ctor of slist
From: Christoph Mathys (eraserix_at_[hidden])
Date: 2008-12-03 04:55:20
Hi!
I have an object containing an interprocess slist (wrapped in a simple
template) which I first construct outside shared memory. Then I want
to push_front this object into a slist lying inside shared memory. And
I get an interprocess::bad_alloc exception from the lists copy
constructor. If I don't use the slist's copy ctor but something like
this->assign(x.begin(), x.end()), the code runs through (the list was
always empty in the test).
I use gcc 4.2.4 on linux 2.6.24 (ubuntu 8.04). Boost 1.36
What am I doning wrong?
Christoph
Following the throwing code:
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/containers/slist.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
using namespace boost::interprocess;
managed_shared_memory* getSegment() {
static managed_shared_memory segment(create_only, "MySharedMemory", 65536);
return &segment;
}
template<typename T>
struct my_slist {
typedef allocator<T, managed_shared_memory::segment_manager> ShmemAllocator;
typedef slist<T, ShmemAllocator> List;
my_slist() : m_list(ShmemAllocator(getSegment()->get_segment_manager())) { }
void push_front(const T& obj)
{ m_list.push_front(obj); }
List m_list;
};
struct ListHolder {
my_slist<int> m_slist;
};
typedef my_slist<ListHolder> HolderList;
int main() {
shared_memory_object::remove("MySharedMemory");
HolderList *holderlist =
getSegment()->construct<HolderList>("IntListHolderList")();
ListHolder asdf;
holderlist->push_front(asdf); // exception boost::interprocess::bad_alloc
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk