Click here to Skip to main content
15,895,084 members
Articles / Programming Languages / C++

Buffer Pool \ Object Pool

Rate me:
Please Sign up or sign in to vote.
4.50/5 (18 votes)
18 Jan 20035 min read 128.1K   3.2K   79  
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
{
public:
	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;}
private:
	TCHAR NameOfSomethingOrRather[MAX_PATH];
	int   i;
	float f;
	double d[10];

};

/////////////////////////////////////////////////////////////////////////////
// CDemoDlg dialog

class CDemoDlg : public CDialog
{
// Construction
public:

	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
	//{{AFX_DATA(CDemoDlg)
	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;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDemoDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CDemoDlg)
	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();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// 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.

License

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


Written By
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

Comments and Discussions