470,624 Members | 1,952 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,624 developers. It's quick & easy.

Marshal.AllocHGlobal versus Marshal.AllocCoTaskMem

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/de...us/cpref/html/
frlrfsystemruntimeinteropservicesmarshalclassalloc cotaskmemtopic.asp

http://msdn.microsoft.com/library/de...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
Nov 21 '05 #1
2 4241
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
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
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:eZ*************@TK2MSFTNGP12.phx.gbl...
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Stefan | last post: by
4 posts views Thread by **Developer** | last post: by
2 posts views Thread by scottt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.