[Boost.Interprocess] int key and flat_multimap_index
A couple of beginner questions on basic_managed_heap_memory:
1) I want to access elements in the contiguous memory segment by
using an int key, rather than a char string. Can I declare something
like this:
typedef basic_managed_heap_memory <
int, /* my key is an integer */
rbtree_best_fit
Robert Kubrick wrote:
A couple of beginner questions on basic_managed_heap_memory:
1) I want to access elements in the contiguous memory segment by using an int key, rather than a char string. Can I declare something like this:
typedef basic_managed_heap_memory < int, /* my key is an integer */ rbtree_best_fit
, flat_map_index managed_heap_memory;
I need to lookup objects using an external integer ID but the ID can have any value (ie, does not match the 0-N array element order of my memory segment).
No sorry, named allocation is only availables for chars. One workaround thing you can do is to allocate anonymous objects in the managed segment and create another map-like structure pointing to those anonymous objects. More inefficient, I know, but I can't think another way. Anyway, I think you've shown me a good use case to study the possibility of using non-char indexes (something I suspect will require a lot of work, because all the code supposes string keys).
2) If I want to insert multiple objects with the same char* name (ala multimap) can I create a flat_multimap_index?
You can't. Names must be unique because it should identify a unique named object. Otherwise, we wouldn't be capable to find an object correctly. Regards, Ion
On Aug 17, 2008, at 5:15 AM, Ion Gaztañaga wrote:
Robert Kubrick wrote:
A couple of beginner questions on basic_managed_heap_memory: 1) I want to access elements in the contiguous memory segment by using an int key, rather than a char string. Can I declare something like this: typedef basic_managed_heap_memory < int, /* my key is an integer */ rbtree_best_fit
, flat_map_index managed_heap_memory; I need to lookup objects using an external integer ID but the ID can have any value (ie, does not match the 0-N array element order of my memory segment).
No sorry, named allocation is only availables for chars. One workaround thing you can do is to allocate anonymous objects in the managed segment and create another map-like structure pointing to those anonymous objects. More inefficient, I know, but I can't think another way. Anyway, I think you've shown me a good use case to study the possibility of using non-char indexes (something I suspect will require a lot of work, because all the code supposes string keys).
2) If I want to insert multiple objects with the same char* name (ala multimap) can I create a flat_multimap_index?
You can't. Names must be unique because it should identify a unique named object. Otherwise, we wouldn't be capable to find an object correctly.
A subset of objects could have the same name, but each object would be assigned to a unique slot in the segment. A multimap search on the non-unique name would return an equal_range object.
Regards,
Ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Robert Kubrick wrote:
You can't. Names must be unique because it should identify a unique named object. Otherwise, we wouldn't be capable to find an object correctly.
A subset of objects could have the same name, but each object would be assigned to a unique slot in the segment. A multimap search on the non-unique name would return an equal_range object.
But you couldn't erase an single object by name, something that some interprocess classes use internally. Sorry but named creation was built under the assumption of unique names. Regards, Ion
participants (2)
-
Ion Gaztañaga
-
Robert Kubrick