CMemAllocator Class


CMemAllocator class hierarchy

This class provides support for IMemAllocator by using the new operator to allocate memory. Derived from CBaseAllocator, it overrides the CBaseAllocator::Alloc member function to allocate a single block of memory large enough to hold all the requested data areas, and then allocates (using the new operator) a CMediaSample object for each requested buffer pointing into the data area.

The CBaseInputPin and CBaseOutputPin classes instantiate CMemAllocator objects as the default allocator if no other suitable allocator is provided.

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

Member Functions
Name Description
Alloc Allocates memory for a media sample (overrides CBaseAllocator::Alloc).
CMemAllocator Constructs a CMemAllocator object.
ReallyFree Frees memory when called from the destructor (or from Alloc when reallocating for new size or count).

Overridable Member Functions
Name Description
Free Indicates an overridden CBaseAllocator::Free member function, called when a decommit operation is complete to free memory.

Implemented IMemAllocator Methods
Name Description
CreateInstance Creates new instances of CMemAllocator in the factory template.
SetProperties Sets the number of media samples and the size of each.


CMemAllocator::Alloc

CMemAllocator Class

Allocates a media sample object.

HRESULT Alloc(void);

Return Values

Returns an HRESULT value.

Remarks

This member function instantiates CMediaSample objects, adds them to the m_lFree data members, and updates the m_lAllocated count. This member function is called from IMemAllocator::Commit when becoming active.


CMemAllocator::CMemAllocator

CMemAllocator Class

Constructs a CMemAllocator object.

CMemAllocator(
  TCHAR * pName,
  LPUNKNOWN lpUnk,
  HRESULT * phr
  );

Parameters
pName
Name of the allocator object.
lpUnk
Pointer to LPUNKNOWN.
phr
Pointer to the general OLE return value. Note that this value is changed only if this function fails.
Return Values

No return value.

Remarks

This constructor is passed to CBaseAllocator::CBaseAllocator, which initializes the data members.


CMemAllocator::CreateInstance

CMemAllocator Class

Creates new instances of CMemAllocator in the factory template.

static CUnknown *CreateInstance(
  LPUNKNOWN pUnk,
  HRESULT *phr
  );

Parameters
pUnk
Pointer to the IUnknown interface.
phr
Pointer to the HRESULT value into which to place resulting information.
Return Values

Returns the pUnkRet parameter, which is a CUnknown class object.


CMemAllocator::Free

CMemAllocator Class

Frees memory for a media sample object.

HRESULT Free(void);

Return Values

No return value.

Remarks

This member function overrides the pure virtual CBaseAllocator::Free member function called when a decommit operation has completed. Memory is actually freed in ReallyFree, which is called from the destructor, so this function is not used in this class.


CMemAllocator::ReallyFree

CMemAllocator Class

Releases all media samples in the free list.

void ReallyFree (void);

Return Values

No return value.

Remarks

The CMemAllocator class holds memory until the object is actually deleted. This member function can be overridden to handle freeing media samples when a decommit occurs.

This member function is protected.


CMemAllocator::SetProperties

CMemAllocator Class

Determines the size, number, and alignment of blocks.

HRESULT SetProperties(
  ALLOCATOR_PROPERTIES * pRequest,
  ALLOCATOR_PROPERTIES * pActual
  );

Parameters
pRequest
Requested allocator properties.
pActual
Allocator properties actually set.
Return Values

Returns an HRESULT value.

Remarks

The pRequest parameter is filled in by the caller with the requested values for the count, number, and alignment as specified by the ALLOCATOR_PROPERTIES structure. The pActual parameter is filled in by the allocator with the closest values it can provide for the request. This member function cannot be called unless the allocator has been decommitted using the IMemAllocator::Decommit method.

This member function replaces SetCountAndSize in previous releases.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.