I am building a DirectShow Filter in Delphi 6 Pro using the DSPACK DirectShow component library. In their Push Source Filter example, for some items they use CoTaskMemAlloc(), especially with allocating memory for items used in Windows API calls such as video bitmap info headers (PVIDEOINFOHEADER) and buffers used in O/S file operations such as ReadFile, etc. Other items are allocated using the usual (Object).Create() call or by creating dynamic arrays directly.
What are the rules/guidelines for when you must use CoTaskMemAlloc() inside a DirectShow filter?
This SO reply by @Vinay gives the succinct answer that it should be used with any memory that will crosses process boundaries:
But I would like to know if there are any common memory allocation mistakes I am likely to make in my DirectShow filter, especially when rendering or providing data via input/output pins, due to my failure to use CoTaskMemAlloc().
CoTaskMemAlloc
would help with memory that crosses process boundaries. My understanding is that you useCoTaskMemAlloc
whenever you pass ownership of memory to another COM object. – David Heffernan