> If I am writing a .NET library using managed C++, when exactly do I have
> to
> decorate a pointer with the __gc decorator?
Well, pointers to managed objects are always __gc. So mostly, you don't have
to be explicit where you point to managed objects though it doesn't hurt.
Suppose though, that you have a managed class and that that managed class
has a member which has an unmanaged type - say integer. If you needed a
pointer to that integer then you'd need to mark the pointer as __gc. That's
because that ordinary integer is set on the managed heap and it can move out
from under you.
I hope this helps. I had hoped to come up with a more definitive, less
annecdotal explanation for you. I scanned the book "Essential Guide to
Managed Extensions for C++" hoping to find some advice from on high that I
could quote. What there is in the book is a whole _chapter_ on the topic.
I'd recommend the book, but depending on your release schedule, you might
want to wait for a book on C++/CLI which supplants MC++ in VS.Net 2005
Regards,
Will
TT (Tom Tempelaere) - 08 Mar 2005 16:25 GMT
Thank you William, I understand now.
Tom Tempelaere.
ismailp - 08 Mar 2005 22:13 GMT
you may need to use __gc on managed arrays, too.
i'd also recommend the same thing; wait for C++/CLI. you can get its
beta1 or latest ctp and enjoy using new language. there is no __gc in
C++/CLI.
_B - 07 Jun 2005 08:10 GMT
>.... depending on your release schedule, you might
>want to wait for a book on C++/CLI which supplants MC++ in VS.Net 2005
>
>Regards,
>Will
I had just posted a query about books on C++/CLI. Looks like you just
answered it. I'm surprised that no one got the jump on the 2005
compiler release.
Well, in the absence of a book, are there any good web-based
references on the subject?
William DePalo [MVP VC++] - 07 Jun 2005 15:09 GMT
> On Tue, 8 Mar 2005 11:03:51 -0500, "William DePalo [MVP VC++]"
> I had just posted a query about books on C++/CLI. Looks like you just
[quoted text clipped - 3 lines]
> Well, in the absence of a book, are there any good web-based
> references on the subject?
This is an introduction:
http://msdn.microsoft.com/msdnmag/issues/05/02/PureC/default.aspx
This details the differences between MC++ and C++/CLI:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/Tra
nsGuide.asp
They should get you started. You can try googling for more, perhaps
searching for articles written by Lippman or ones on "C++/CLI"
Regards,
Will