|
Boost Users : |
Subject: Re: [Boost-users] Can Boot MultiIndex help me?
From: Ernest Zaslavsky (ernest.zaslavsky_at_[hidden])
Date: 2015-07-23 00:11:31
No, it is not (unfortunately)
As stated here: http://www.boost.org/doc/libs/1_58_0/libs/multi_index/doc/tutorial/indices.html#rnd_indices
They do not provide memory contiguity, a property of std::vectors by which elements are stored adjacent to one another in a single block of memory.
-----Original Message-----
From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Paolo Bolzoni
Sent: Wednesday, July 22, 2015 4:31 PM
To: boost-users_at_[hidden]
Subject: [Boost-users] Can Boot MultiIndex help me?
Dear list,
I needed a data structure such that:
- a list of POD structs (with an Id and other fields) stays in contiguous memory. This is required because I need to pass this block of memory to a C function.
- the order of this POD structs is irrelevant.
- I need to access to each element from the Id quickly.
So I implemented a class using std::map and std::vector; the vector contains the structs and the map associate between the ids and the vector position.
The vector ensures C memory layout and the map gives the elements from the Id quickly.
To delete an element I copy the last element in its position, update the map, and pop the vector back (of course there are some special cases, like deleting the last element... but you got the point) To add an element I push it back to the vector and update the map.
It works fine, but a colleague mentioned that boost multiindex can do a similar job. I checked the documentation, but I am not sure I can build an index on a vector. Is that possible? Thanks.
Your faithfully,
Paolo
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
[Read More]<http://feeds.feedburner.com/~r/sizmek-blog/~6/1>
[http://www.sizmek.com/Sizmek.png]<http://www.sizmek.com/>
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