Boost logo

Boost Users :

Subject: Re: [Boost-users] [interprocess] Performance problem with managed_shared_memory
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2009-11-06 11:10:45


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


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