Note that there are some explanatory texts on larger screens.

plurals
  1. POboost::multi_index_container - equal_range values
    text
    copied!<p>I have been trying a few solutions using the boost interprocess library with a map and now a multi_index_container in shared memory. With the multi_index_container, is there any way other than to iterate over the values returned from equal_range. I was hoping to retrieve a subset of results from my non_unique index (station name e.g. ST0012345) and then find/get the actual measurement type I need (e.g. Temperature).</p> <p>I need to retrieve the unique pointID value for the measurement point (e.g. ST0012345SMD10000456.VoltsA = pointID - 45789) to insert the measurement value into a data Historian. I liked the idea of multi_index_container as our message payloads contain ~100 to 200 measurements for the one station in an array so I thought I could do one call to the shared memory container which will contain 500,000+ items and then lookup each measurement point from a much smaller list using the long unique string name.</p> <p>It seems from the reading I have done that I may only be able to iterate over the smaller list returned from the multi_index_container rather than do a get/find.</p> <p>If that is the case, am I better off to stick to my original shared memory map solution (which I have working) which as I said contains 500,000+ items of longish strings to match on to retrieve the pointID required by our data historian. There is a high data rate with 200 points being processed per second (I found my data map lookup could reach 2000 lookups per second in a test environment).</p> <p>Also, if I do use the map, is there any harm in having several maps in shared memory e.g. a map for Sydney stations (~300,000 points), a map for Newcastle stations (~200,000 points).</p> <p>Below is the code for my program which is retrieving items from a seperate process that created the multi_index_container.</p> <pre><code>using namespace boost::interprocess; using namespace System; namespace bmi = boost::multi_index; typedef managed_shared_memory::allocator&lt;char&gt;::type char_allocator; typedef basic_string&lt;char, std::char_traits&lt;char&gt;, char_allocator&gt;shm_string; struct tag { shm_string name; shm_string stn; shm_string mtype; int id; tag( const char *name_ , const char_allocator &amp;a , const char *stn_ , const char_allocator &amp;b , const char *mtype_ , const char_allocator &amp;d , int id_) : name(name_, a), stn(stn_, b), mtype(mtype_, d), id(id_) {} }; struct name{}; struct stn{}; struct mtype{}; struct id{}; typedef bmi::multi_index_container&lt; tag, bmi::indexed_by&lt; bmi::ordered_unique &lt;bmi::tag&lt;name&gt;, BOOST_MULTI_INDEX_MEMBER(tag,shm_string,name)&gt;, bmi::ordered_non_unique&lt; bmi::tag&lt;stn&gt;,BOOST_MULTI_INDEX_MEMBER(tag,shm_string,stn)&gt; &gt;, managed_shared_memory::allocator&lt;tag&gt;::type &gt; tag_set; typedef tag_set::iterator iterator; int main(array&lt;System::String ^&gt; ^args) { try{ managed_shared_memory segment(open_only,"MySharedMemory"); offset_ptr&lt;tag_set&gt; es = segment.find&lt;tag_set&gt;("My MultiIndex Container").first; char_allocator alloc_inst(segment.get_allocator&lt;char&gt;()); shm_string key_object(alloc_inst); key_object = "ST0012345SMD10000456"; std::pair&lt;tag_set::index&lt;stn&gt;::type::iterator, tag_set::index&lt;stn&gt;::type::iterator&gt; values = es-&gt;get&lt;stn&gt;().equal_range(key_object); while(values.first != values.second) { std::cout &lt;&lt; values.first-&gt;name &lt;&lt; " -- " &lt;&lt;" ("&lt;&lt;values.first-&gt;stn&lt;&lt;","&lt;&lt;values.first-&gt;mtype&lt;&lt;")\n"; ++values.first; } char_allocator alloc_inst2(segment.get_allocator&lt;char&gt;()); shm_string key_object2(alloc_inst2); key_object2 = "ST0012345SMD10000456.VoltsA"; ///// is there any way something like the following can be done rather than the above iterator ????? iterator it = values-&gt;get&lt;name&gt;(key_object2); &lt;------- ???????????????????????? } catch(const std::exception &amp;exc){ std::cerr &lt;&lt; "Exception caught: " &lt;&lt; exc.what(); throw; } Sleep(3000); return 0; </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload