This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
STL vector question
- To: gcc at gcc dot gnu dot org
- Subject: STL vector question
- From: Alexander Zvyagin <zvyagin at mail dot cern dot ch>
- Date: Thu, 2 Mar 2000 22:11:29 +0100 (CET)
Hi!
I have question related to STL vector.
Please, take a look at this simple code
{
int a1[111];
vector<int> a2(111);
a1[1]=0; // int[] access
a2[1]=0; // access to vector<int>[]
}
I believed that access time both to a1[1] and a2[2] (if we compile the code
with -O2 or -O3 optimisation) must be the same, but it seems I was wrong.
Access to a1[1] is 4 times faster than to a2[1].
a1[1]=0 is equivalent to *( ((int*)a1)+1 ) = 0
These are declarations from stl_vector.h:
reference operator[](size_type n) { return *(begin() + n); }
iterator begin() { return start; }
So a2[1]=0 must be equivalent to *( ((int*)start)+1)=0
But the real codes (check assembler instructions) differ! What I missed?
Or is it g++ bug?
I checked all this stuff with egcs-1.1.2.
Thanks in advance,
Alexander Zvyagin.