$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] [interprocess] Shared memory compile problem
From: Po-Chun (u901815_at_[hidden])
Date: 2009-04-23 14:21:05
Thanks for the response, Ion.
Is there any hash set container for the shared memory?
Po-Chun
On Apr 21, 12:54 pm, Ion Gaztañaga <igaztan..._at_[hidden]> wrote:
> Po-Chunwrote:
> > 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 mailing list
> Boost-us..._at_[hidden]http://listarchives.boost.org/mailman/listinfo.cgi/boost-users