Muokkaa

Jaa


CBaseAllocator.Alloc method

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The Alloc method allocates memory for the buffers.

Syntax

virtual HRESULT Alloc();

Parameters

This method has no parameters.

Return value

Returns one of the following HRESULT values.

Return code Description
S_FALSE
Buffer requirements have not changed.
S_OK
Buffer requirements have changed.
VFW_E_SIZENOTSET
Buffer requirements were not set.

Remarks

This method is called by the CBaseAllocator::Commit method.

In the base class, this method does not allocate any memory. It returns an error if the buffer requirements were not set, S_FALSE if the requirements have not changed, and S_OK if the requirements have changed.

A derived class should override this method to perform the actual memory allocation. Typically, the derived class will perform the following steps:

  1. Call the base class implementation, to determine whether the memory truly needs allocating.
  2. Allocate memory.
  3. Create CMediaSample objects that contain chunks of memory from step 2.
  4. Add each CMediaSample object to the list of free samples (CBaseAllocator::m_lFree).

For an example, see CMemAllocator::Alloc.

Requirements

Requirement Value
Header
Amfilter.h (include Streams.h)
Library
Strmbase.lib (retail builds);
Strmbasd.lib (debug builds)

See also

CBaseAllocator Class