Reputation: 2304
The DirectX Media Objects(DMO) documentation advised that, for sake of efficiency, buffers holding media samples (supporting the IMediaBuffer
interface) should be pooled instead of being constantly created/destroyed:
The simplest solution is to allocate a new buffer for each sample, although doing so is inefficient.
A better solution is to implement an object to manage a pool of buffers. To do this, write code in the Release method of your IMediaBuffer implementation that calls a method of your buffer manager (instead of deleting itself) when the reference count drops to zero. The buffer manager can then maintain a list of pointers to allocated buffer objects. Create a method in your buffer manager to check the list of free buffers and return a pointer so that your application can access buffers when needed.
Now that DMO has been superseded by Media Foundation Transforms (MFT), I can't find the same advice in the documentation. Is this pooling strategy something that should still be considered when managing the equivalent buffer objects (this time implementing the IMFMediaBuffer
interface)?
Upvotes: 4
Views: 347
Reputation: 1515
See this webcast : Introduction to Windows Media Architecture
You will learn more about memory management Inside MediaFoundation.
For my experience with MediaFoundation, the MediaFoundation pooling strategy is very good.
Upvotes: 2
Reputation: 69642
The pooling strategy still reduces overall performance overhead but there are a few important things to keep in mind:
MFCreateSample
: the API returns a new sample created on API-managed internal pool of sample objectsThat is, even if you not pool, you still get some pooling for free and the API itself helps you with small things like this. Your reasonable approach for accurate resource management still makes sense and would not hurt, of course, especially that documentation is not so much detailed on how it is doing the optimizations on its end.
Also, a good example of COM object pool implementation is DirectShow's CMemAllocator
implementation contained in Windows SDK 7.x samples in \Samples\multimedia\directshow\baseclasses\amfilter.h
Upvotes: 4