Click here to Skip to main content
15,922,325 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Avoid flickering in list control? Pin
Michael Dunn28-Nov-01 9:56
sitebuilderMichael Dunn28-Nov-01 9:56 
QuestionAre there faster accessing arrays than vectors? Pin
Chambers28-Nov-01 9:00
Chambers28-Nov-01 9:00 
AnswerRe: Are there faster accessing arrays than vectors? Pin
Christian Graus28-Nov-01 12:32
protectorChristian Graus28-Nov-01 12:32 
AnswerRe: Are there faster accessing arrays than vectors? Pin
Todd Smith28-Nov-01 14:44
Todd Smith28-Nov-01 14:44 
AnswerRe: Are there faster accessing arrays than vectors? Pin
Chambers29-Nov-01 8:50
Chambers29-Nov-01 8:50 
GeneralRe: Are there faster accessing arrays than vectors? Pin
Chris Losinger29-Nov-01 11:08
professionalChris Losinger29-Nov-01 11:08 
GeneralRe: Are there faster accessing arrays than vectors? Pin
Todd Smith29-Nov-01 12:11
Todd Smith29-Nov-01 12:11 
GeneralRe: Are there faster accessing arrays than vectors? Pin
Todd Smith29-Nov-01 12:24
Todd Smith29-Nov-01 12:24 
This is scary. Here's my test program

int data[10];
int sum = 0;
for (int i = 0; i < 10; i++)
{
    sum += data[i];
}

std::vector<int> vdata(10);
for (int j = 0; j < 10; j++)
{
    sum += vdata[i];
}


and here's what the difference between the two assembler dumps

sum = data[i] becomes

mov         ecx,dword ptr [ebp-3Ch]
mov         edx,dword ptr [ebp-38h]
add         edx,dword ptr [ebp+ecx*4-34h]
mov         dword ptr [ebp-38h],edx


and the vector method sum += vdata[i] becomes

mov         eax,dword ptr [ebp-3Ch]
push        eax
lea         ecx,[ebp-4Ch]
call        @ILT+525(std::vector<int,std::allocator<int> >::operator[]) (00401212)
mov         ecx,dword ptr [ebp-38h]
add         ecx,dword ptr [eax]
mov         dword ptr [ebp-38h],ecx

"@ILT+525(std::vector<int,std::allocator<int> >::operator[]) (00401212)"
push        ebp
mov         ebp,esp
sub         esp,44h
push        ebx
push        esi
push        edi
push        ecx
lea         edi,[ebp-44h]
mov         ecx,11h
mov         eax,0CCCCCCCCh
rep stos    dword ptr [edi]
pop         ecx
mov         dword ptr [ebp-4],ecx
mov         ecx,dword ptr [ebp-4]
call        @ILT+475(std::vector<int,std::allocator<int> >::begin) (004011e0)
mov         ecx,dword ptr [ebp+8]
lea         eax,[eax+ecx*4]
pop         edi
pop         esi
pop         ebx
add         esp,44h
cmp         ebp,esp
call        __chkesp (0040e8b0)
mov         esp,ebp
pop         ebp
ret         4

"@ILT+475(std::vector<int,std::allocator<int> >::begin) (004011e0)"
push        ebp
mov         ebp,esp
sub         esp,44h
push        ebx
push        esi
push        edi
push        ecx
lea         edi,[ebp-44h]
mov         ecx,11h
mov         eax,0CCCCCCCCh
rep stos    dword ptr [edi]
pop         ecx
mov         dword ptr [ebp-4],ecx
mov         eax,dword ptr [ebp-4]
mov         eax,dword ptr [eax+4]
pop         edi
pop         esi
pop         ebx
mov         esp,ebp
pop         ebp
ret


I think I know where the 2 seconds went OMG | :OMG:

Todd Smith


GeneralRe: There are faster accessing arrays than vectors! Pin
Chambers30-Nov-01 2:39
Chambers30-Nov-01 2:39 
GeneralVery strange behavior in ActiveX control, pleas help Pin
Bill Wilson28-Nov-01 8:51
Bill Wilson28-Nov-01 8:51 
QuestionHow to map return-key(enter) from combobox? Pin
Pony28-Nov-01 7:52
Pony28-Nov-01 7:52 
GeneralSoftware Documentation Pin
28-Nov-01 7:48
suss28-Nov-01 7:48 
GeneralRe: Software Documentation Pin
Mike Nordell28-Nov-01 17:28
Mike Nordell28-Nov-01 17:28 
GeneralTo Christian Graus & Nish Pin
Karavaev Denis28-Nov-01 7:21
Karavaev Denis28-Nov-01 7:21 
GeneralRe: To Christian Graus & Nish Pin
Chris Losinger28-Nov-01 7:46
professionalChris Losinger28-Nov-01 7:46 
GeneralRe: Who are these guys? Pin
Masaaki Onishi28-Nov-01 9:47
Masaaki Onishi28-Nov-01 9:47 
GeneralRe: Who are these guys? Pin
Karavaev Denis28-Nov-01 17:20
Karavaev Denis28-Nov-01 17:20 
GeneralRe: To Christian Graus & Nish Pin
Karavaev Denis28-Nov-01 17:23
Karavaev Denis28-Nov-01 17:23 
GeneralRe: OK, This is a tricky one! Pin
Masaaki Onishi28-Nov-01 17:34
Masaaki Onishi28-Nov-01 17:34 
GeneralI think, I'm an idiot .... Pin
Karavaev Denis28-Nov-01 17:47
Karavaev Denis28-Nov-01 17:47 
GeneralRe: I think, I'm an idiot .... Pin
Masaaki Onishi28-Nov-01 18:44
Masaaki Onishi28-Nov-01 18:44 
GeneralRe: I think, I'm an idiot .... Pin
Karavaev Denis28-Nov-01 19:01
Karavaev Denis28-Nov-01 19:01 
GeneralRe: I think, I'm an idiot .... Pin
Nish Nishant28-Nov-01 18:45
sitebuilderNish Nishant28-Nov-01 18:45 
GeneralRe: Ooops, I forgot to say... Pin
Masaaki Onishi29-Nov-01 7:03
Masaaki Onishi29-Nov-01 7:03 
Generalgt Pin
28-Nov-01 5:34
suss28-Nov-01 5:34 

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.