|
From: | Ilia Mirkin |
Subject: | Re: [Discuss-gnuradio] ANCI-C vs Gnuradio/C++ speeeed |
Date: | Fri, 12 May 2006 20:07:13 -0400 |
User-agent: | Internet Messaging Program (IMP) H3 (4.0.3) |
Quoting al davis <address@hidden>:
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
[Prev in Thread] | Current Thread | [Next in Thread] |