C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[49140] Re:정확한 delay함수.
김형준 [phenix] 1760 읽음    2007-05-02 12:00
A counter is a general term used in programming to refer to an incrementing variable. Some systems include a high-resolution performance counter that provides high-resolution elapsed times.

If a high-resolution performance counter exists on the system, the QueryPerformanceFrequency function can be used to express the frequency, in counts per second. The value of the count is processor dependent. On some processors, for example, the count might be the cycle rate of the processor clock.

The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter (if one exists on the system). By calling this function at the beginning and end of a section of code, an application essentially uses the counter as a high-resolution timer. For example, suppose that QueryPerformanceFrequency indicates that the frequency of the high-resolution performance counter is 50,000 counts per second. If the application calls QueryPerformanceCounter immediately before and immediately after the section of code to be timed, the counter values might be 1500 counts and 3500 counts, respectively. These values would indicate that .04 seconds (2000 counts) elapsed while the code executed.

윗글은 MSDN에 있는내용입니다.

아래는 코드구루에서 가져온 class입니다.

class CElapsed
{
   private :
      int Initialized;
      __int64 Frequency;
      __int64 BeginTime;

   public :
      CElapsed()
      {
        Initialized = QueryPerformanceFrequency((LARGE_INTEGER*)&Frequency);
      }

      BOOL Begin()
      {
         if(!Initialized )
         return 0;

         return QueryPerformanceCounter((LARGE_INTEGER*)&BeginTime);
      }

      double End()
      {
         if(!Initialized )
         return 0.0;

         __int64 endtime;
         QueryPerformanceCounter((LARGE_INTEGER*)&endtime);

         __int64 elapsed = endtime - BeginTime;

         return (double)elapsed / (double)Frequency;
      }

      BOOL Available()
      {
         return Initialized;
      }

      __int64 GetFreq()
      {
         return Frequency;
      }
};

end 부분을 수정(while loop을 이용)하면 조금더 정확한 delay를 얻을 수 있습니다.
window os의 한계로 정확한 시간을 멈춘다는 것은 어렵지 않겠나 싶군요.



별다섯개 님이 쓰신 글 :
: mS단위의 정확한 delay를 구현하는 방법이 있나요? 혹은 uS까지도 가능한지 모르겠지만요.
:
: void delay(int d)
: {
:     double a,b,c;
:
:     a = timeGetTime();
:
:     while(1)
:     {
:         b = timeGetTime();
:         c = b-a;
:         if(c>=delay)break;
:         //Application->ProcessMesages();
:     }
: }
:
: 이런식의 함수는 window의 다른 process들이 같이 돌기 때문에 정확한 시간을 구현하지
: 못하겠더라구요..

+ -

관련 글 리스트
49014 정확한 delay함수. 별다섯개 1747 2007/04/21
49140     Re:정확한 delay함수. 김형준 1760 2007/05/02
49142         Re:Re: 사용시 주의하셔야합니다. 김상구.패패루 1209 2007/05/02
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.