Click here to Skip to main content
11,933,180 members (63,756 online)
Click here to Skip to main content


78 bookmarked

Buffer Pool \ Object Pool

, 18 Jan 2003
An article on optimization of the use of dynamic memory.
// DemoDlg.h : header file

#if !defined(AFX_DEMODLG_H__C77D5BA1_B9E2_4C03_B79D_BA54D2E894EF__INCLUDED_)
#define AFX_DEMODLG_H__C77D5BA1_B9E2_4C03_B79D_BA54D2E894EF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "BufferPool.h"
#include "ObjectPool.h"

class SomeType
	SomeType(){i = 1;f = 0.2F;d[0] = f;}
    virtual ~SomeType(){}
	virtual int DoSomethingOrRather(){memset(NameOfSomethingOrRather,0,MAX_PATH); return i;}
	virtual float  GetTheFlaot(){return f;}
	static int OneMoreMethod(){return 1;}
	TCHAR NameOfSomethingOrRather[MAX_PATH];
	int   i;
	float f;
	double d[10];


// CDemoDlg dialog

class CDemoDlg : public CDialog
// Construction

	CObjectPool<SomeType> SomeTypeObjectPool;

	CBufferPool m_BuffPoolObj;

	UINT	m_BPFreeCount;
	UINT	m_RegFreeCount;
	UINT	m_BPAllocateCount;
	UINT	m_RegAllocateCount;

	__int64		m_nBPTotalTime;

	__int64		m_nRegTotalTime;

	CDemoDlg(CWnd* pParent = NULL);	// standard constructor

	virtual ~CDemoDlg();

// Dialog Data
	enum { IDD = IDD_DEMO_DIALOG };
	CProgressCtrl	m_RegularAllocationProgress;
	CProgressCtrl	m_BuffPollProgress;
	CString	m_BPFreeStatic;
	CString	m_RegFreeStatic;
	CString	m_BPAllocateStatic;
	CString	m_RegAllocateStatic;
	CString	m_BPAvTime;
	CString	m_RegAvTime;
	CString	m_BPTotalTime;
	CString	m_RegTotalTime;
	DWORD	m_nBufferSize;
	DWORD	m_nMaximumBuffers;
	DWORD	m_nNumberOfOperations;
	DWORD	m_nNumberOfThreads;
	UINT	m_nMinNumberOfSegments;
	UINT	m_nMaxNumberOfSegments;
	UINT	m_nInitialNumberOfSegments;
	float	m_nFreeBuffersPrecentForSegmentDeletion;
	UINT	m_nBuffersPerSegment;

	// ClassWizard generated virtual function overrides
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support

// Implementation
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnTestButton();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnTestBpButton();
	afx_msg void OnTestGlobalButton();

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DEMODLG_H__C77D5BA1_B9E2_4C03_B79D_BA54D2E894EF__INCLUDED_)

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.151126.1 | Last Updated 19 Jan 2003
Article Copyright 2003 by Uri Twig
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid