Click here to Skip to main content
11,790,816 members (48,480 online)
Click here to Skip to main content
Add your own
alternative version

Buffer Pool \ Object Pool

, 18 Jan 2003 100.7K 2.8K 78
An article on optimization of the use of dynamic memory.

#include "stdafx.h"
#include "PreciseTimer.h"

bool CPreciseTimer::sm_bInit = false;
bool CPreciseTimer::sm_bPerformanceCounter;
__int64 CPreciseTimer::sm_i64Freq;

CPreciseTimer::CPreciseTimer() : m_i64Start(0), m_i64Elapsed(0), m_bRunning(false)
	//Only if not already initialized
	if(false == sm_bInit)
		//Initializing some static variables dependent on the system just once
		if(TRUE == QueryPerformanceFrequency(&liFreq))
			//Only if the system is supporting High Performance
			sm_i64Freq = ((__int64)liFreq.HighPart << 32) + (__int64)liFreq.LowPart;
			sm_bPerformanceCounter = true;
			sm_bPerformanceCounter = false;
		sm_bInit = true;

void CPreciseTimer::StartTimer()
	if(true == sm_bPerformanceCounter)
		m_i64Start = ((__int64)m_liCount.HighPart << 32) + (__int64)m_liCount.LowPart;
		//Transform in microseconds
		(m_i64Start *= 1000000) /= sm_i64Freq;
		//Transform milliseconds to microseconds
		m_i64Start = (__int64)GetTickCount() * 1000;
	m_bRunning = true;

void CPreciseTimer::StopTimer()
	m_bRunning = false;

__int64 CPreciseTimer::GetTime()
	if(true == m_bRunning)
	return m_i64Elapsed;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Uri Twig
Web Developer
Israel Israel
4 years expirience coding C++ with MFC & STL and coding C for Windows XP/2K internals (Drivers).

I Love what I do.

For pastime activities:
Fun & Games

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1509028.1 | Last Updated 19 Jan 2003
Article Copyright 2003 by Uri Twig
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid