Click here to Skip to main content
15,905,028 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ optimization problem Pin
Ravi Bhavnani1-Jul-04 14:10
professionalRavi Bhavnani1-Jul-04 14:10 
GeneralRe: C++ optimization problem Pin
PJ Arends1-Jul-04 14:12
professionalPJ Arends1-Jul-04 14:12 
GeneralRe: C++ optimization problem Pin
Ryan Binns1-Jul-04 14:17
Ryan Binns1-Jul-04 14:17 
GeneralRe: C++ optimization problem Pin
Johan Rosengren1-Jul-04 19:44
Johan Rosengren1-Jul-04 19:44 
GeneralRe: C++ optimization problem Pin
Antony M Kancidrowski2-Jul-04 2:11
Antony M Kancidrowski2-Jul-04 2:11 
GeneralRe: C++ optimization problem Pin
Johan Rosengren2-Jul-04 2:20
Johan Rosengren2-Jul-04 2:20 
GeneralRe: C++ optimization problem Pin
Antony M Kancidrowski2-Jul-04 2:35
Antony M Kancidrowski2-Jul-04 2:35 
GeneralRe: C++ optimization problem Pin
Paul Ranson2-Jul-04 3:01
Paul Ranson2-Jul-04 3:01 
Your question implies that you are doing,
for (int ii = 0; ii < a_vector.size (); ++ii )
{
    a_vector [ ii ].DoSomething () ;
}

You may find that operator [] on vector is more expensive than size. Especially given that in many cases an interator resolves to a plain old pointer, so both the dereference and the increment are cheap.

Perhaps you could measure your way and also,
A_VECTOR::iterator it ;
A_VECTOR::iterator itE = a_vector.end () ;
for ( it = a_vector.begin () ; it != itE; ++it )
{
    (*it).DoSomething () ;
}

But it's cleanest by far to write,
class A_TYPE { ... } ;
vector<A_TYPE> a_vector ;
for_each ( a_vector.begin (), a_vector.end (), mem_fun_ref ( &A_TYPE::DoSomething )) ;

or some variant of function, functor etc that suits your code. I think this is probably potentially the fastest since the compiler has all the information to inline everything.

Paul
QuestionC++ in &quot;Hardware structures&quot; stand point question: Does the ALU handle any floading points operations? or will the processor let the FPU handles them? Pin
Link26001-Jul-04 13:29
Link26001-Jul-04 13:29 
AnswerRe: C++ in &quot;Hardware structures&quot; stand point question: Does the ALU handle any floading points operations? or will the processor let the FPU handles them? Pin
Ryan Binns1-Jul-04 14:21
Ryan Binns1-Jul-04 14:21 
GeneralDynamic controls Pin
richiebabes1-Jul-04 11:47
richiebabes1-Jul-04 11:47 
GeneralRe: Dynamic controls Pin
Yawar Maajed1-Jul-04 12:22
Yawar Maajed1-Jul-04 12:22 
GeneralRe: Dynamic controls Pin
richiebabes1-Jul-04 12:30
richiebabes1-Jul-04 12:30 
GeneralRe: Dynamic controls Pin
Yawar Maajed1-Jul-04 13:11
Yawar Maajed1-Jul-04 13:11 
GeneralWindow title bar - detecting drag end Pin
Anonymous1-Jul-04 11:39
Anonymous1-Jul-04 11:39 
GeneralRe: Window title bar - detecting drag end Pin
Anonymous1-Jul-04 11:41
Anonymous1-Jul-04 11:41 
GeneralRe: Window title bar - detecting drag end Pin
Yawar Maajed1-Jul-04 12:19
Yawar Maajed1-Jul-04 12:19 
GeneralRe: Window title bar - detecting drag end Pin
Yawar Maajed1-Jul-04 12:21
Yawar Maajed1-Jul-04 12:21 
GeneralRe: Window title bar - detecting drag end Pin
Ravi Bhavnani1-Jul-04 13:42
professionalRavi Bhavnani1-Jul-04 13:42 
QuestionHow do you get the path to the WIndows desktop? Pin
Terry O'Nolley1-Jul-04 11:02
Terry O'Nolley1-Jul-04 11:02 
AnswerRe: How do you get the path to the WIndows desktop? Pin
Yawar Maajed1-Jul-04 11:19
Yawar Maajed1-Jul-04 11:19 
GeneralRe: How do you get the path to the WIndows desktop? Pin
Terry O'Nolley1-Jul-04 12:07
Terry O'Nolley1-Jul-04 12:07 
AnswerRe: How do you get the path to the WIndows desktop? Pin
palbano1-Jul-04 11:20
palbano1-Jul-04 11:20 
QuestionHow to write a program to auto-fill an HTML page? Pin
Anonymous1-Jul-04 10:42
Anonymous1-Jul-04 10:42 
AnswerRe: How to write a program to auto-fill an HTML page? Pin
Anders Molin1-Jul-04 13:51
professionalAnders Molin1-Jul-04 13:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.