The DirectX Media Objects(DMO) documentation advised that, for sake of efficiency, buffers holding media samples (supporting the
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.
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 objects
That 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