Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Buffer Pool \ Object Pool

, 18 Jan 2003
An article on optimization of the use of dynamic memory.
// BufferPool.h: interface for the CBufferPool class.
//
//////////////////////////////////////////////////////////////////////

#ifndef BUFFER_POOL_H
#define BUFFER_POOL_H

#include "link.h"

//struct _SEGMENT;
typedef struct _SEGMENT *PSEGMENT;


class CBufferPool  
{
public:
	CBufferPool(){}
	virtual ~CBufferPool(){}
	bool  Create(	IN const unsigned int   nBufferSize,
					IN const unsigned int	nNumberOfBuffersInSegment,
					IN const unsigned int	nNumberOfSegmentsStrat,
					IN const unsigned int	nNumberOfSegmentsLowMark,
					IN const unsigned int	nNumberOfSegmentsHighMark = -1,
					IN const double			lfRatioForSegmentDeletion = 0.333);
	
	void* Allocate();
	void  Free(const void* pBuffer);

	void Destroy();

private:
	bool AllocateSegment();
	void FreeSegment(IN PSEGMENT p_segment);

	//member variables
	DLINK			m_SegmentsListHead;


	
	unsigned int	m_nNumberOfBuffersInSegment;
	unsigned int	m_nNumberOfSegmentsStrat;
	unsigned int	m_nNumberOfSegmentsLowMark;
	unsigned int	m_nNumberOfSegmentsHighMark;
	unsigned int	m_nBufferSize;

	UINT			m_nNumberOfSegments;
	UINT			m_nFreeBuffers;
	

	PSEGMENT		m_pSegmentCandidateForDeletion;
	unsigned int	m_nCandidateDeletionLimit;

	CRITICAL_SECTION			m_CriticalSection;	
};

#endif //BUFFER_POOL_H

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

Share

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

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