Regarding Marshal.AllocHGlobal versus Marshal.AllocCoTaskMem Does anyone
know the circumstances in which one should use one over the other?
http://msdn.microsoft.com/library/de...-us/cpref/html /
frlrfsystemruntimeinteropservicesmarshalclassalloc cotaskmemtopic.asp
http://msdn.microsoft.com/library/de...-us/dllproc/ba s
e/overlapped_str.asp
Above are the relevant links to MSDN. The details are fairly sparse in
terms of useage guidance.
Thanks in advance.
-Mike
If you're passing the pointer to an API that specifically says the
memory should be allocated with CoTaskMemAlloc, then you should use
AllocCoTaskMem. In most other situations AllocHGlobal will work just
as well.
Mattias
I've been researching this a little further and it seems to me that both
functions allocate memory from the default per process heap. The only
difference is that AllocCoTaskMem (derived from IMalloc / CoTaskMemAlloc() )
is used by the COM allocator and / or when the programmer wishes to allocate
memory for a COM object. In all other scenarios (such as passing pointers
to unmanaged memory to unmanaged DLLs) then either function is ok to use.
http://msdn.microsoft.com/library/de...us/dngenlib/ht
ml/msdn_virtmm.asp
So i'm going to stick with AllocHGlobal since im not dealing with COM
objects.
Still would appreciate any further insight anyone might have.
Thanks
-Mike