[interprocess] [container] Can iterator hold raw-pointer instead of offset_ptr?
Hi there, When putting containers in shared memory, offset_ptr is used internally, and IIUC, the iterator of the container will also use offset_ptr. But it seems to me that in most cases we only use iterator locally rather than putting those iterators in shared memory as well, so the plain-old-raw-pointer is sufficient and hopefully more efficient for iterator's usage. What do you think?
El 28/04/2013 9:06, TONGARI escribió:
Hi there,
When putting containers in shared memory, offset_ptr is used internally, and IIUC, the iterator of the container will also use offset_ptr. But it seems to me that in most cases we only use iterator locally rather than putting those iterators in shared memory as well, so the plain-old-raw-pointer is sufficient and hopefully more efficient for iterator's usage.
What do you think?
Unless you use vector, the speed improvement might not be very different, as when iterating with such special "raw iterator", you need to traverse elements in shared memory that are linked using offset_ptr (a linked list, tree...). I guess you can get more speed with vector if a raw iterator is used, but you can always obtain the address of the first element and use raw pointers. I agree that assignment, construction, dereference etc. of iterators with raw pointers will be faster (e.g. you need a container of iterators pointing to elements stored in shared memory containers). I guess the speed advantage would be application-dependent. Best, Ion
Hi Ion,
2013/4/28 Ion Gaztañaga
El 28/04/2013 9:06, TONGARI escribió:
Hi there,
When putting containers in shared memory, offset_ptr is used internally, and IIUC, the iterator of the container will also use offset_ptr. But it seems to me that in most cases we only use iterator locally rather than putting those iterators in shared memory as well, so the plain-old-raw-pointer is sufficient and hopefully more efficient for iterator's usage.
What do you think?
Unless you use vector, the speed improvement might not be very different, as when iterating with such special "raw iterator", you need to traverse elements in shared memory that are linked using offset_ptr (a linked list, tree...). I guess you can get more speed with vector if a raw iterator is used, but you can always obtain the address of the first element and use raw pointers.
The speed gain that I expected might be quite similar for both vector & list. Both can save an addition for each dereference operation.
I agree that assignment, construction, dereference etc. of iterators with raw pointers will be faster (e.g. you need a container of iterators pointing to elements stored in shared memory containers). I guess the speed advantage would be application-dependent.
If it's a possible improvement and won't break anything, I still hope it can make its place.
Regards,
On 28/04/13 09:06, TONGARI wrote:
Hi there,
When putting containers in shared memory, offset_ptr is used internally, and IIUC, the iterator of the container will also use offset_ptr. But it seems to me that in most cases we only use iterator locally rather than putting those iterators in shared memory as well, so the plain-old-raw-pointer is sufficient and hopefully more efficient for iterator's usage.
What do you think?
I have seen some people force a shared memory segment to be mapped at the same address in all processes so that they could avoid using offset_ptr and get better performance. If you're looking for performance, that might be an option as well. I don't know how much boost.interprocess makes it easy to do this.
El 29/04/2013 9:54, Mathias Gaunard escribió:
On 28/04/13 09:06, TONGARI wrote:
Hi there,
When putting containers in shared memory, offset_ptr is used internally, and IIUC, the iterator of the container will also use offset_ptr. But it seems to me that in most cases we only use iterator locally rather than putting those iterators in shared memory as well, so the plain-old-raw-pointer is sufficient and hopefully more efficient for iterator's usage.
What do you think?
I have seen some people force a shared memory segment to be mapped at the same address in all processes so that they could avoid using offset_ptr and get better performance.
If you're looking for performance, that might be an option as well. I don't know how much boost.interprocess makes it easy to do this.
You can do it. Using fixed_managed_shared_memory all pointers are raw pointers. You can map it in a fixed address. Ion
participants (3)
-
Ion Gaztañaga
-
Mathias Gaunard
-
TONGARI