Click here to Skip to main content
16,011,358 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Someone please Help Pin
PJ Arends24-Mar-06 5:03
professionalPJ Arends24-Mar-06 5:03 
GeneralRe: Someone please Help Pin
Shoaib Patel26-Mar-06 17:39
Shoaib Patel26-Mar-06 17:39 
GeneralRe: Someone please Help Pin
PJ Arends26-Mar-06 18:42
professionalPJ Arends26-Mar-06 18:42 
GeneralRe: Someone please Help Pin
Shoaib Patel26-Mar-06 19:04
Shoaib Patel26-Mar-06 19:04 
QuestionArray Vs Pointers Pin
vikramlinux24-Mar-06 2:14
vikramlinux24-Mar-06 2:14 
AnswerRe: Array Vs Pointers Pin
vikramlinux24-Mar-06 2:15
vikramlinux24-Mar-06 2:15 
GeneralRe: Array Vs Pointers Pin
Ștefan-Mihai MOGA24-Mar-06 2:23
professionalȘtefan-Mihai MOGA24-Mar-06 2:23 
AnswerRe: Array Vs Pointers Pin
Roger Stoltz24-Mar-06 2:48
Roger Stoltz24-Mar-06 2:48 
vikrams wrote:
for(i=0; i < 10;i++)
value=*(ptr+i);

for(i=0; i < 10;i++)
value=*ptr++;


I don't know if the compiler is able to optimize this, but if we disregard from eventual compiler optimizations the second for-loop will be faster.

Consider the first for-loop.
For each round-trip you...
1) increase the value of i which is held in a register
2) load the address of ptr into another register
3) add the value of i to the register holding ptr Dead | X|
4) assign to value using indirect addressing

Now consider the second for-loop.
For each round-trip you...
1) increase the value of i which is held in a register
2) assign the value of i using indirect addressing

There's more to it than this, but I've omitted parts that are the same for both for-loops such as calculation of the size of the data type pointed to and similar.

It's possible that the compiler is smart enough to optimize the first for-loop so it would generate the same machine code as if you would have written ptr[i], which I beleive would generate the fastest execution, but you have to look at the generated assembler code to be able to figure that one out. An exercise for the reader.

Hope this helps
--
Roger


It's supposed to be hard, otherwise anybody could do it!
GeneralRe: Array Vs Pointers Pin
vikramlinux24-Mar-06 2:55
vikramlinux24-Mar-06 2:55 
GeneralRe: Array Vs Pointers Pin
Roger Stoltz24-Mar-06 3:30
Roger Stoltz24-Mar-06 3:30 
GeneralRe: Array Vs Pointers Pin
PJ Arends24-Mar-06 5:12
professionalPJ Arends24-Mar-06 5:12 
GeneralRe: Array Vs Pointers Pin
Roger Stoltz24-Mar-06 5:34
Roger Stoltz24-Mar-06 5:34 
QuestionCFileDialog Pin
Steingrebe24-Mar-06 2:11
Steingrebe24-Mar-06 2:11 
AnswerRe: CFileDialog Pin
Roger Stoltz24-Mar-06 2:24
Roger Stoltz24-Mar-06 2:24 
GeneralRe: CFileDialog Pin
Steingrebe24-Mar-06 11:07
Steingrebe24-Mar-06 11:07 
AnswerRe: CFileDialog Pin
Roger Stoltz27-Mar-06 3:00
Roger Stoltz27-Mar-06 3:00 
AnswerRe: CFileDialog Pin
Hamid_RT24-Mar-06 2:25
Hamid_RT24-Mar-06 2:25 
AnswerRe: CFileDialog Pin
Hamid_RT24-Mar-06 2:59
Hamid_RT24-Mar-06 2:59 
QuestionMIDL2039 warning Pin
skuu24-Mar-06 2:04
skuu24-Mar-06 2:04 
AnswerRe: MIDL2039 warning Pin
Roger Stoltz24-Mar-06 2:09
Roger Stoltz24-Mar-06 2:09 
GeneralRe: MIDL2039 warning Pin
skuu24-Mar-06 18:33
skuu24-Mar-06 18:33 
AnswerRe: MIDL2039 warning Pin
Roger Stoltz27-Mar-06 3:05
Roger Stoltz27-Mar-06 3:05 
QuestionUsing resources files under Visual C++ Pin
Allad24-Mar-06 2:04
Allad24-Mar-06 2:04 
AnswerRe: Using resources files under Visual C++ Pin
Maximilien24-Mar-06 2:28
Maximilien24-Mar-06 2:28 
GeneralRe: Using resources files under Visual C++ Pin
Allad24-Mar-06 3:28
Allad24-Mar-06 3:28 

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.