473,811 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When to add __gc decorator

Hey everyone,

If I am writing a .NET library using managed C++, when exactly do I have to
decorate a pointer with the __gc decorator?

Thanks,
--
Tom Tempelaere.
Nov 17 '05 #1
5 1101
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThot mailD.Tcom|/\|@P$0_|\|_>
wrote in message news:DB******** *************** ***********@mic rosoft.com...
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
Nov 17 '05 #2
Thank you William, I understand now.

Tom Tempelaere.
Nov 17 '05 #3
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.

Nov 17 '05 #4
_B
On Tue, 8 Mar 2005 11:03:51 -0500, "William DePalo [MVP VC++]"
<wi***********@ mvps.org> wrote:
.... 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?

Nov 17 '05 #5
"_B" <_B@nomail.or g> wrote in message
news:gt******** *************** *********@4ax.c om...
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
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?


This is an introduction:

http://msdn.microsoft.com/msdnmag/is...C/default.aspx

This details the differences between MC++ and C++/CLI:

http://msdn.microsoft.com/library/de...TransGuide.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
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

41
2881
by: John Marshall | last post by:
How about the following, which I am almost positive has not been suggested: ----- class Klass: def __init__(self, name): self.name = name deco meth0: staticmethod def meth0(x):
30
2514
by: Ron_Adam | last post by:
I was having some difficulty figuring out just what was going on with decorators. So after a considerable amount of experimenting I was able to take one apart in a way. It required me to take a closer look at function def's and call's, which is something I tend to take for granted. I'm not sure this is 100%, or if there are other ways to view it, but it seems to make sense when viewed this way. Is there a way to do this same thing...
3
2431
by: Ron_Adam | last post by:
Ok... it's works! :) So what do you think? Look at the last stacked example, it process the preprocess's first in forward order, then does the postprocess's in reverse order. Which might be usefull. Interesting in any case. Making decorators with this class is a snap!
6
1404
by: Michele Simionato | last post by:
could ildg wrote: > I think decorator is a function which return a function, is this right? > e.g. The decorator below if from http://www.python.org/peps/pep-0318.html#id1. > > def accepts(*types): > def check_accepts(f): > assert len(types) == f.func_code.co_argcount
2
2573
by: microsoft | last post by:
Hi All, I am fairly new to Managed C++ extensions. I started trying to implement a interface defined in a C# project, in C++. The problem was with passing value arrays from c# to c++. I found examples on the web which worked, but found mine didn't. After narrowing down the interface I found what I believe to be the problem. The order of the parameters! The code below shows the function that does not compile named QueryPositionsForward....
5
1567
by: kchui | last post by:
I have a C# interface as: public interface IBar{ void TestParam(ref StringCollection a, ref int b); } And I need to implment it in Managed C++, and I try to implement it as: public __gc class Foo : public IBar { public:
5
1818
by: Doug | last post by:
I am looking at using the decorator pattern to create a rudimentary stored proc generator but am unsure about something. For each class that identifies a part of the stored proc, what if I want to add a value dynamically. I'm including some code to show what I mean. This is real basic on what I want to do: using System; namespace ClassLibrary1 {
0
942
by: craig.conboy | last post by:
Using MC++ .Net 2.0, with the CLR Profiler (from Microsoft) I am seeing that 3 blocks of memory, each ~48MB in size, being allocated by some code that initializes a managed array. It is a jagged array of string arrays, and contains some nullptr items, sample code below. Looking at the IL using .Net Reflector also below I think I see why. This issue is easy to work around by using a gcnew array<String^{} instead of a nullptr, but is not...
4
2474
by: thomas.karolski | last post by:
Hi, I would like to create a Decorator metaclass, which automatically turns a class which inherits from the "Decorator" type into a decorator. A decorator in this case, is simply a class which has all of its decorator implementation inside a decorator() method. Every other attribute access is being proxied to decorator().getParent(). Here's my attempt: -------------------------------------------------------
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10395
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10130
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6887
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.