Boost logo

Boost Users :

From: alexmark (talamar.lands_at_[hidden])
Date: 2006-12-07 18:28:08


Hi,
I'd like to allocate objects directly in shared memory (not within STL-like
container) in the way like that:

struct X {
    int a;
    int b;
};

typedef boost::interprocess::node_allocator<X, A_POOL_SIZE,
managed_shared_memory::segment_manager > AllocType;

int main (...)
{
    // create shared memory
    managed_shared_memory sharm (create_only, "a_name", SOME_SIZE);
    // create allocator object
    AllocType alloc_object (sharm.get_segment_manager());

    // allocate memory for object instance taking it from the allocator's
pool
    X* p = detail::get_pointer(alloc_object.allocate(1));
    // invoke the constructor
    alloc_object.construct(p, X());

    // obtain the handle
    sharm.get_handle_from_address(p);

    // now the handle is passed to another application to let it access the
shared object
    // ....

}

Is it correct to do so? Will it work?

TYA


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