Microsoft DirectX 8.0

CMemAllocator Class

CMemAllocator class hierarchy

Implements an allocator that supports the IMemAllocator interface.

Declaration: Amfilter.h

This class derives from CBaseAllocator. For more information about allocators, refer to the documentation for CBaseAllocator.

Protected Member Variables
m_pBufferPointer to the memory block that contains the buffers.
Protected Methods
FreeCalled during a decommit operation.
ReallyFreeReleases the memory for the buffers.
AllocAllocates memory for the buffers.
Public Methods
CMemAllocatorConstructor method.
~CMemAllocatorDestructor method.
CreateInstanceCreates a new instance of the CMemAllocator class.
IMemAllocator Methods
SetPropertiesSpecifies the number of buffers to allocate and the size of each buffer.

CMemAllocator.m_pBuffer

CMemAllocator Class

Pointer to the memory block that contains the buffers.

Syntax

LPBYTE m_pBuffer; 

Remarks

Sample buffers are calculated as offsets from this pointer.

CMemAllocator::Alloc

CMemAllocator Class

Allocates memory for the buffers.

Syntax

HRESULT Alloc(void); 

Return Value

Returns one of the HRESULT values shown in the following table.

S_OKSuccess.
E_OUTOFMEMORYInsufficient memory.
VFW_E_SIZENOTSETBuffer requirements were not set.

Remarks

This method is called by the CBaseAllocator::Commit method. It allocates a contiguous block of memory sufficient for the buffer requirements given in the SetProperties method.

CMemAllocator::CMemAllocator

CMemAllocator Class

Constructor method.

Syntax

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

Parameters

pName
Pointer to a string containing the name of the allocator.
pUnk
Pointer to the owner of this object. If the object is aggregated, pass a pointer to the aggregating object's IUnknown interface. Otherwise, set this parameter to NULL.
phr
Pointer to a variable that receives an HRESULT value indicating the success or failure of the method.

CMemAllocator::~CMemAllocator

CMemAllocator Class

Destructor method.

Syntax

~CMemAllocator(void);

Syntax

This method overrides the base-class destructor to call Decommit and ReallyFree.

CMemAllocator::CreateInstance

CMemAllocator Class

Creates a new instance of the CMemAllocator class.

Syntax

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

Parameters

pUnk
Pointer to the owner of this object. If the object is aggregated, pass a pointer to the aggregating object's IUnknown interface. Otherwise, set this parameter to NULL.
phr
Pointer to a variable that receives an HRESULT value indicating the success or failure of the method.

Return Value

Returns a pointer to a new CMemAllocator object, typed as a CUnknown object.

CMemAllocator::Free

CMemAllocator Class

Called during a decommit operation.

Syntax

void Free(void); 

Remarks

This method overrides the pure virtual method CBaseAllocator::Free, which is called during a decommit operation. In the CMemAllocator class, this method does not do anything. Memory is freed in the destructor method, by calling the ReallyFree method.

CMemAllocator::ReallyFree

CMemAllocator Class

Releases the memory for the buffers.

Syntax

void ReallyFree (void); 

Remarks

The CMemAllocator class holds memory until the object is deleted.

CMemAllocator::SetProperties

CMemAllocator Class

Specifies the number of buffers to allocate and the size of each buffer.

Syntax

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

Parameters

pRequest
Pointer to an ALLOCATOR_PROPERTIES structure that contains the buffer requirements.
pActual
Pointer to an ALLOCATOR_PROPERTIES structure that receives the actual buffer properties.

Return Value

Returns one of the HRESULT values shown in the following table.

S_OKSuccess.
E_POINTERNULL pointer argument.
VFW_E_ALREADY_COMMITTEDCannot change allocated memory while the filter is active.
VFW_E_BADALIGNAn invalid alignment was specified.
VFW_E_BUFFERS_OUTSTANDINGOne or more buffers are still active.

Remarks

This method overrides the CBaseAllocator::SetProperties method.

The buffer alignment, specified by the cbAlign member of the ALLOCATOR_PROPERTIES structure, must be an even power of two.