Marshal.AllocHGlobal versus Marshal.AllocCoTaskMem

  • 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

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
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
 
Regarding Marshal.AllocHGlobal versus Marshal.AllocCoTaskMem Does anyone
know the circumstances in which one should use one over the other?

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
 
Thanks Mattias. Just as you say, so far i've found that either works just
as well. I'm thinking maybe ill stick to using CoTaskMemAlloc whenever i
need to pass a pointer to an API and AllocHGlobal in all other circumstances
that may arise.
-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top