Hi Andrew,
> Thanks for you response Tomas.
>
[quoted text clipped - 4 lines]
> 1. So will the "nogc_ManagedClass" that I had in the example compile
> to CIL, and the "UnmanagedClass" complile to x86 code?
A class does not compile to code. *Methods* in the class, will, though.
That's the key point. MC++ makes a very explicit exception about what is
managed data (i.e. __gc/__nogc classes) and what is managed code (methods
that compile to CIL or x86).
So you can have a __nogc class whose *methods* are compiled to CIL, but the
class itself is still unmanaged (meaning it gets allocated in the stack or
the unmananged heap), or __nogc classes that contain both managed and
unmanaged methods. A __gc class, on the other hand, only has managed
methods.
So, when you compile code with /clr, classes by default remain __nogc, but
the methods they contain might be compiled as managed code. That's perfectly
valid.
> 2. If I want to use a __gc class from my "nogc_ManagedClass" I will
> need to have the pointer to that class wrapped with gcroot<T>?
Depends on what you mean by "use". If you mean contain a reference to the
__gc class as a field of your __nogc class, then the answer is yes. However,
any managed methods the __nogc class have can manipulate a __gc class
directly, without gcroot.

Signature
Tomas Restrepo
tomasr@mvps.org
Andrew - 17 Nov 2004 12:52 GMT
> Hi Andrew,
>
[quoted text clipped - 30 lines]
> any managed methods the __nogc class have can manipulate a __gc class
> directly, without gcroot.
Tomas,
I am working a project that is currently written in c++. I need to
modify this project so that it uses some components written in c#.
This modification needs to be done with as little effect in the
existing code as possible. I am considering have my current c++ code
have a pointer to a nogc class and the nogc class have a pointer to a
gc class. This gc class will then communicate with some c#
assemblies.
Is there any value in only including the /clr compile option on the
nogc and gc classes and leaving it off the rest of the classes in the
project? Based on your last response, it seems that including the
/clr option on the entire project should have little effect on the old
c++ classes.
If I include the /clr option on either a subset of classes or the
entire project what effect does this have on linking? Can incremental
links still be done? I heard from a co-worker that adding the /clr
option to a project means incremental links can no longer be done.
This is a large project, so this could slow down development
considerably.
Tomas Restrepo \(MVP\) - 20 Nov 2004 18:13 GMT
Hi Andrew,
> I am working a project that is currently written in c++. I need to
> modify this project so that it uses some components written in c#.
[quoted text clipped - 9 lines]
> /clr option on the entire project should have little effect on the old
> c++ classes.
It might have little impact on the source code, but it might have an impact
on performance, in some cases (depends a lot on what your code is like, so
it's not easy to say upfront). I suggest you do a few tests to see what
works best for you.
> If I include the /clr option on either a subset of classes or the
> entire project what effect does this have on linking? Can incremental
> links still be done? I heard from a co-worker that adding the /clr
> option to a project means incremental links can no longer be done.
> This is a large project, so this could slow down development
> considerably.
If this is an issue, then I'd recommend moving the code you're compiling
with /clr to a different module (i.e. isolate it to it's own DLL). That way,
it would be easier to maintain. In general, in cases like this, keeping the
code isolated will mean the minimal impact on your compiling process.

Signature
Tomas Restrepo
tomasr@mvps.org