This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for

This is an abstract base class that implements the basic mechanisms for an allocator with a fixed number of fixed-size buffers.

The number of buffers and their size can be changed using the CBaseAllocator::SetPropertiesmember function when an input pin and an output pin negotiate the allocator between them.

The class provides the basic functionality for a memory allocator by implementing the IMemAllocatorinterface.

It provides support for managing a list of CMediaSampleobjects (or objects derived from this class), including support for the IMemAllocator::Commitand IMemAllocator::Decommitmethods, and blocking the IMemAllocator::GetBuffermethod.

Any class derived from this class (such as CMemAllocator) must create CMediaSampleobjects, which this base class does not.

A signaling mechanism employing a semaphore is used so that if there are no samples, a thread can wait until there are samples or until the allocator is decommitted. The m_lFreeand m_hSemmember variables are used to implement this simple signaling mechanism as follows.

When a thread calls CBaseAllocator::GetBufferand there are no samples available, m_lWaitingis incremented and the thread calls the Win32 WaitForSingleObjectfunction on the semaphore indicated by m_hSem.

When a sample is freed (by the IUnknown::Releasemethod returning the reference count to zero) or CBaseAllocator::Decommitis called and m_lWaitingis nonzero, the Win32 ReleaseSemaphorefunction is called on m_hSemwith a release count of m_lWaiting, and m_lWaitingis reset to zero.

All member functions in this class that return HRESULTand accept a pointer as a parameter return E_POINTER when passed a null pointer.

Protected Data Members

Member Description


TRUE if the buffers have changed; otherwise, FALSE.


If TRUE, the allocator is in a state in which all IMemAllocator::GetBuffermethods fail.

The IMemAllocator::SetPropertiesmethod is the only member function permitted to operate in this state.


If TRUE, the decommit process completes upon the return of all media samples.

Until the decommit process has completed, any calls to IMemAllocator::GetBufferreturn E_OUTOFMEMORY.


Semaphore for signaling.


Agreed alignment of the buffer.


Number of buffers actually allocated.


Established number of buffers to provide.


List of CMediaSampleobjects that are currently free (free list).


Agreed prefix of the buffer (precedes value returned by IMediaSample::GetPointer).


Size of each buffer.


Count of threads waiting for samples.

Member Functions

Member function Description


Constructs a CBaseAllocatorobject.


Notifies a waiting thread that a sample is available on the free list.


Increments the m_lWaitingdata member to indicate that a thread is waiting for a sample.

Overrideable Member Functions

Member function Description


Allocates memory, instantiates CMediaSampleobjects, and adds them to the m_lAllocatedand m_lFreedata members.


Decommits memory when the last buffer is freed.

Implemented IMemAllocator Methods

Method Description


Allocates memory by calling the CBaseAllocator::Allocmember function, which you must override.


Releases any resources and enters the inactive state.

Blocking calls to IMemAllocator::GetBuffershould return with an error value, and all further calls to GetBufferfail when in the inactive state.


Retrieves a container for a sample.


Determines the size, number, and alignment of blocks.


Releases the CMediaSampleobject.


Specifies a desired number of blocks, size of the blocks, and block alignment figure. This method returns the actual values for the same.

Implemented INonDelegatingUnknown Methods

Method Description


Passes out pointers to any interfaces added to the derived filter class.


Windows Embedded CE Windows CE 2.12 and later
Windows Mobile Windows Mobile Version 5.0 and later
Note Microsoft DirectShow applications and DirectShow filters have different include file and Library requirements
For more information, see Setting Up the Build Environment