|
Boost : |
Subject: [boost] [interprocess] [bimap] Using raw pointers
From: Matias Capeletto (matias.capeletto_at_[hidden])
Date: 2013-01-25 14:05:46
Hello,
Currently Boost.Bimap does not work with interprocess allocators
because it uses references to connect the views and the core. I want
to change this but avoid any performance hit and I am wondering what
is the best way to do it.
It will be easy if Bimap interface will use .left() and .right()
functions to access the map views (then I could just init the views at
each call like Boost.MultiIndex get() index function does) but I am
stuck with the left and right members (and I actually like them).
So, what I want to be able to do is the following:
template<class Bimap>
class left_type {
Bimap* core;
public:
left_type(Bimap* c) : core(c) {};
...
};
template<class Bimap> class right_type {...};
template<class LeftKey,class RightKey>
class bimap {
public:
left_type<bimap> left;
right_type<bimap> right;
bimap() : left(this), right(this) {}
};
This will not work because I am not using the proper offset_pointer
abstraction, but I would love to be able to avoid it. In the case of
Bimap, these pointers are very easy to maintain.
Will it be possible to add an extension point to Boost.Interprocess to
allow this idiom?
Something like adding a call to the end of priv_find_impl of
segment_manager so user classes can rewire themselves when they are
loaded from shared memory. For example:
template<class T>
void rewire_after_loading_from_shared_memory(T* t) { }
...
template <class T>
std::pair<T*, size_type> priv_find_impl (const CharType* name, bool lock) {
// find ret pointer
T* t_ret = static_cast<T*>(ret) ;
if( t_ret ) rewire_after_loading_from_shared_memory( t_ret );
return std::pair<T*, size_type>(t_ret ,sz);
}
...
Or maybe a better place. Then I will be able to rewire the map views
pointers to the core if they are different from it:
template<class L, class R>
void rewire_after_loading_from_shared_memory(bimap<L,R>* t) { t->rewire(); }
If this is not possible because inherent limitations of the
interprocess mechanisms, do you know a good way to make Boost.Bimap
compatible with its allocators?
Thanks,
Best regards
Matias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk