GCC vector element access pointers in C++

Jonathan Wakely jwakely.gcc@gmail.com
Tue Jan 26 10:52:00 GMT 2016

On 26 January 2016 at 09:13, Marius Miknis wrote:
> Hi Marc,
> Thanks for such a quick reply, I appreciate it.
> Yes I am trying to speed up my testing in debug as working with point clouds of +600,000 points stored in vectors is really really slow, thus using _ MyFirst and _MyLast removes all the dereferencing/accessing overheads as I work directly with pointers and can just increment pointer addresses, plus even if the vector gets resized _ MyFirst and _MyLast are not affected.

We don't provide direct access to members like that and never will.

> I did look through the stl_vector.h but it sadly seems that I can not use ._M_impl._M_start. I am aware that compiler will remove all the overheads in release but currently in debugging I need a fast way to access and move through the vector.

GCC doesn't have "release" and "debug".  Compile with -Og and you can
still debug the result easily, but a lot of the abstraction penalty is

Or you could compile with -fno-access-control but I don't recommend it.

I am surprised that when accessing 600000+ points you will even notice
the cost of doing v.data() and v.data+v.size() once to calculate those
pointers each time the vector is modified. It certainly shouldn't be
"really really slow".

More information about the Gcc-help mailing list