STL vector question
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Thu Mar 2 13:44:00 GMT 2000
> But the real codes (check assembler instructions) differ! What I missed?
Since you did not say what assembler code you got, it is hard to tell
what you are missing. I slightly modified your code to read
#include <vector>
void foo(int*);
void foo(vector<int>&);
int main()
{
int a1[111];
vector<int> a2(111);
a1[1]=0; // int[] access
foo(a1);
a2[1]=0; // access to vector<int>[]
foo(a2);
}
so that the store to a1 and a2 is not considered dead at optimization,
and also to allow finding the assembler code easier. With gcc 2.95.2,
on i586-pc-linux-gnu, using '-O2 -fno-exceptions', I get the code
fragment
call fill_n__H3ZPiZUiZi_X01X11RCX21_X01
addl $16,%esp
movl %eax,-452(%ebp) ; this is the end of a2 construction
movl $0,-440(%ebp) ; a1[1] = 0
addl $-12,%esp
leal -444(%ebp),%eax ; push a1 for foo
pushl %eax
call foo__FPi
movl -456(%ebp),%eax ; eax = _M_start
addl $16,%esp ; belongs to foo call
movl $0,4(%eax) ; _M_start[1] = 0
addl $-12,%esp
leal -456(%ebp),%eax ; push a2 for foo
pushl %eax
call foo__FRt6vector2ZiZt9allocator1Zi
So the access to a2 has an additional indirection, because the vector
is a wrapper object around the array. Apart from that, I can see no
difference.
Regards,
Martin
More information about the Gcc
mailing list