Click here to Skip to main content
15,899,825 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalabout allocator Pin
vividtang8-May-04 21:16
vividtang8-May-04 21:16 
GeneralRe: about allocator Pin
toxcct9-May-04 5:54
toxcct9-May-04 5:54 
GeneralNewbie string question Pin
MikeUofPhx8-May-04 17:00
MikeUofPhx8-May-04 17:00 
GeneralRe: Newbie string question Pin
Anonymous8-May-04 20:27
Anonymous8-May-04 20:27 
GeneralRe: Newbie string question Pin
John R. Shaw8-May-04 22:13
John R. Shaw8-May-04 22:13 
GeneralRe: Newbie string question Pin
MikeUofPhx9-May-04 13:41
MikeUofPhx9-May-04 13:41 
GeneralOLE DB 'IColumnsInfo2' problem Pin
KalliMan8-May-04 13:06
KalliMan8-May-04 13:06 
QuestionWhich of these methods is more efficient? Pin
Joe Smith IX8-May-04 12:48
Joe Smith IX8-May-04 12:48 
Hi all,

This might be a simple question, and you might say that both ways have their own pros and cons (and the pros and cons are so minor, that they are negligible, therefore they are virtually equally efficient). But sometimes I wonder if every single bit of memory and every cpu cycle count, which one is better?

Thanks for any input.

<br />
// myArray is an array of CMyObject<br />
// GetValue() simply returns an int member from CMyObject, no calculation<br />
// method 1<br />
// repetitive calls, but no additional local variable<br />
for(int i=0; i<myArray.GetSize(); i++)<br />
{<br />
if(myArray.GetAt(i).GetValue()==1) { Function1(); }<br />
else if(myArray.GetAt(i).GetValue()==2) { Function2(); } }<br />
else { Function3(); }<br />
}<br />
<br />
// method 2<br />
// no repetitive calls, but additional local variable<br />
for(int i=0; i<myArray.GetSize(); i++)<br />
{<br />
int nValue = myArray.GetAt(i).GetValue();<br />
if(nValue==1) { Function1(); }<br />
else if(nValue==2) { Function2(); }<br />
else { Function3(); }<br />
}<br />

AnswerRe: Which of these methods is more efficient? Pin
Gary R. Wheeler8-May-04 13:39
Gary R. Wheeler8-May-04 13:39 
AnswerRe: Which of these methods is more efficient? Pin
Prakash Nadar8-May-04 22:35
Prakash Nadar8-May-04 22:35 
AnswerRe: Which of these methods is more efficient? Pin
Paul Ranson9-May-04 1:15
Paul Ranson9-May-04 1:15 
AnswerRe: Which of these methods is more efficient? Pin
Ravi Bhavnani9-May-04 4:29
professionalRavi Bhavnani9-May-04 4:29 
AnswerRe: Which of these methods is more efficient? Pin
Joe Woodbury9-May-04 7:59
professionalJoe Woodbury9-May-04 7:59 
GeneralRe: Which of these methods is more efficient? Pin
Tim Smith9-May-04 9:23
Tim Smith9-May-04 9:23 
GeneralRe: Which of these methods is more efficient? Pin
Joe Woodbury9-May-04 9:42
professionalJoe Woodbury9-May-04 9:42 
GeneralRe: Which of these methods is more efficient? Pin
Tim Smith9-May-04 13:47
Tim Smith9-May-04 13:47 
AnswerRe: Which of these methods is more efficient? Pin
Tim Smith9-May-04 9:27
Tim Smith9-May-04 9:27 
GeneralUsing MFC Source Code Question Pin
nm_1148-May-04 8:26
nm_1148-May-04 8:26 
GeneralRe: Using MFC Source Code Question Pin
Joe Woodbury8-May-04 8:41
professionalJoe Woodbury8-May-04 8:41 
GeneralRPC: Problem in sending data Pin
ahsan_a8-May-04 8:17
ahsan_a8-May-04 8:17 
GeneralRe: RPC: Problem in sending data Pin
ahsan_a8-May-04 12:03
ahsan_a8-May-04 12:03 
GeneralRe: RPC: Problem in sending data Pin
Gary R. Wheeler8-May-04 13:42
Gary R. Wheeler8-May-04 13:42 
QuestionAccess WindowProc in MFC? Pin
Anonymous8-May-04 7:04
Anonymous8-May-04 7:04 
GeneralVoid Pin
soul.ripper8-May-04 7:03
soul.ripper8-May-04 7:03 
GeneralRe: Void Pin
Ryan McDermott8-May-04 7:08
Ryan McDermott8-May-04 7:08 

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.