
Moritz escribió:
Hi there,
I have a performance problem using the managed_shared_memory and the interprocess_vector. I attached a minimalistic, compilable example that demonstrates this. I create a vector that contains a simple class and I write into this vector. If the vector is located in the shared_memory this takes much longer than if it is located in the process-local memory. The main difference then is the used allocator. But I can not explain it.
Process shared containers use relative pointers so that each dereference needs additional operations to get the address on each process. Example: T &operator[](size_type idx) { *(start_+ idx;) } start_ is a smart pointer so pointer arithmetic is not trivial. The compiler can't also apply as many optimization as with raw pointers. So this is expected behaviour. You can improve it a bit with: for ( unsigned int i = 0; i < vec->size(); ++i ) { Point3f &f = ( *vec )[i]; f.x = i; f.y = i; f.z = i; } Or even faster obtaining a raw pointer to the first element: Point3f *first = &(*vec )[0]; for ( unsigned int i = 0; i < vec->size(); ++i ) { first[i].x = i; first[i].y = i; first[i].z = i; } Best, Ion