Managed and Unmanaged

C

Creativ

I'm still confused with managed and unmanaged

In VS2005, in the same project with /CLR switch on.

in managed.h
ref class ManagedClass
{
}

in unmanaged.h
class UnmanagedClass
{
}

in Main.cpp
{
ManagedClass^ mc = gcnew ManagedClass; // So this is managed
UnmanagedClass umc;
}

My question is with UnmanagedClass umc; // So this creates a unmanaged
object, on the unmanaged heep? Does that mean all unmanged objects
won't be moved around by GC? (I assume yes since they are on unmanaged
heap).

Is there good reading describing this?
 
W

William DePalo [MVP VC++]

Creativ said:
I'm still confused with managed and unmanaged
OK.

In VS2005, in the same project with /CLR switch on.

in managed.h
ref class ManagedClass
{
}

in unmanaged.h
class UnmanagedClass
{
}

in Main.cpp
{
ManagedClass^ mc = gcnew ManagedClass; // So this is managed
UnmanagedClass umc;
}

My question is with UnmanagedClass umc; // So this creates a unmanaged
object, on the unmanaged heep?

No. Unmanaged heap allocation requires that you use new. As you have written
it, umc resides on the stack.
Does that mean all unmanged objects won't be moved
around by GC?

Using C++/CLI, only objects allocated via gcnew reside on the managed heap.
The garbage collector only ever moves or collects objects on the managed
heap. Native objects are untouched.

Regards,
Will
 

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

Top