|
Boost Users : |
Subject: Re: [Boost-users] [interprocess] Shared memory compile problem
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2009-04-21 12:54:24
Po-Chun wrote:
> I am a new user and try to write some codes with shared memory using
> boost.interprocess.
> Basically, I followed the examples and the allocation seems fine. But
> the use of shared-memory container gave me a bunch of error messages
> related to
> "instantiated from here." during compile. The error seems related to
> the template.
> But I have no idea how to fix it yet. Any suggestion would be helpful.
> Thanks.
set's constructor is equal to std::constructor, but you must pay more
attention because it needs an allocator and set's constructor taking the
allocator takes also the comparison option. You have several C++ errors
in your code (set's template arguments are not correct, for example).
This should compile fine:
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/set.hpp>
#include <boost/cstdint.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <functional>
#include <utility>
struct LongIntLess
{
bool operator()(const boost::uint64_t a, const boost::uint64_t b) const
{
return a < b;
}
};
int main ()
{
using namespace boost::interprocess;
try{
shared_memory_object::remove("SharedMemory");
managed_shared_memory segment
(create_only, "SharedMemory", sizeof(boost::uint64_t)*200);
typedef allocator< boost::uint64_t,
managed_shared_memory::segment_manager>
shmAllocator_t;
typedef set<boost::uint64_t, LongIntLess, shmAllocator_t> shrSet_t;
const shmAllocator_t alloc_inst (segment.get_segment_manager());
shrSet_t *WrSet_1;
WrSet_1 = segment.construct<shrSet_t> ("shrSet_t")
(LongIntLess(), alloc_inst);
WrSet_1->insert(2);
} catch (...){
shared_memory_object::remove("SharedMemory");
throw;
}
shared_memory_object::remove("SharedMemory");
}
Ion
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net