카테고리 없음

빠른코드]포인터로 클래스의 맴버변수1의 멤버변수2를 참조할때, 포인터변수 사용이 더 빠를까?

안녕1999 2018. 9. 15. 23:30

포인터로 클래스의 맴버변수1의 멤버변수2를 참조할때,

맴버변수1를 포인터로 얻어서 처리하는것이 더 빠를까?


ex1)

while(p)

{

if(p->m_Control.Device==Device) <<=== (1)

{

...

}

p=p->next;

}



ex2)

Control *pC;

pC=&(p->m_Control);

while(p)

{

if(pC->Device==Device) <<=== (2)

{

...

}

p=p->next;

}



디스어셈블

2593:             if(p->m_Control.Device==Device)

00520BD2   mov         ecx,dword ptr [ebp-4]

00520BD5   xor         edx,edx

00520BD7   mov         dx,word ptr [ecx+46h]

00520BDB   cmp         edx,dword ptr [ebp+0Ch]

00520BDE   jne         Text_setValue_device_no_func_repeate+0CEh (00520c2e)

2594:             if(pC->Device==Device)

00520BE0   mov         eax,dword ptr [pC]

00520BE3   xor         ecx,ecx

00520BE5   mov         cx,word ptr [eax+6]

00520BE9   cmp         ecx,dword ptr [ebp+0Ch]

00520BEC   jne         Text_setValue_device_no_func_repeate+0CEh (00520c2e)


결론 : 코드가 동일하다.

이유추측 : 2번째 멤버변수 참조(.)는 주소로 표현되기 때문에, 멤버변수를 나타내는 '.'은 연산자가 아니다.