Quoting al davis <[EMAIL PROTECTED]>:

On Friday 12 May 2006 18:24, Ilia Mirkin wrote:
Also, when you do

vector<int> x;
x[0] = 5;

keep in mind that internally it instantiates a new int
object, and then calls operator= on it. The compiler might
optimize this to a certain extent, but certainly not to the
level of simplicity of a single memory access/write.

A good compiler will optimize it that well.

Your code is wrong.  The vector x is of size zero.  It should
crash.

You need:
vector<int> x;
x.reserve(5);
x[0] = 5;

or:
vector<int> x(5);
x[0] = 5;


OK, I suppose I was just giving an *idea* of what I was comparing rather than
fully working compiled code. But you're right -- I just checked the generated
code, and the only difference came from the array being on the stack vs
somewhere on the heap, which is to be expected. I hadn't realized that
compilers had come this far in terms of STL optimization.

 -Ilia



_______________________________________________
Discuss-gnuradio mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to