Marshal.AllocHGlobal versus Marshal.AllocCoTaskMem REVISISTED

  • Thread starter Thread starter Hypnotron
  • Start date Start date
H

Hypnotron

Hello,
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/default.asp?url=/library/en-us/cpref/html /
frlrfsystemruntimeinteropservicesmarshalclassalloccotaskmemtopic.asp
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


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/default.asp?url=/library/en-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
 
Back
Top