472,958 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Managed, Unmanaged, Native Concepts Questions?

Joe
I am trying to get a good understanding of these concepts and how they apply
to code and classes (possibly different). As well as MSIL and Native Code
(x86 assembly).

To facilitate discussion consider the following code.

//////////////////////////////////////////////////
// compiled with /clr

ref class A {
//code and members
};
class B{
//code and members
};

#pragma unmanaged

class C{
//code and members
};

//////////////////////////////////////////////

Are the following comments correct?

Class A
1. Class A is a managed type (because it is gc)
2. Class A code is MSIL executed by the CLR
3. Class A is dynamically allocated with gcnew on the CLR heap (thus garbage
collected);

Class B
1. Class B is a native type (because it does not use new language
constructs)
2. Class B is a unmanaged type (because it is not gc)
3. Class B code is MSIL executed by the CLR
4. Class B is dynamically allocated with "new" on the regular C++ heap (not
gc).

Class C
1. Class C is a native type (because it does not use new language
constructs)
2. Class C is a unmanaged type (because it is not gc)
3. Class C code is X86 assembly code ran directly on the processor
4. Class C code is dynamically allocated the "new" on the regular C++ heap
(not gc).
Note the only difference in B and C is the type of code generated.
Note that Class B is unmanaged even though it occurs because the #pragma
unmanaged statement. That's a bit confusing. Do I have that concept correct?

It you have any other permutations of logic that would be helpful, I would
appreciate them.

Thanks Joe

--

Feb 5 '07 #1
2 1319
Joe schrieb:
I am trying to get a good understanding of these concepts and how they apply
to code and classes (possibly different). As well as MSIL and Native Code
(x86 assembly).

To facilitate discussion consider the following code.

//////////////////////////////////////////////////
// compiled with /clr

ref class A {
//code and members
};
class B{
//code and members
};

#pragma unmanaged

class C{
//code and members
};

//////////////////////////////////////////////

Are the following comments correct?

Class A
1. Class A is a managed type (because it is gc)
2. Class A code is MSIL executed by the CLR
3. Class A is dynamically allocated with gcnew on the CLR heap (thus garbage
collected);

Class B
1. Class B is a native type (because it does not use new language
constructs)
2. Class B is a unmanaged type (because it is not gc)
3. Class B code is MSIL executed by the CLR
4. Class B is dynamically allocated with "new" on the regular C++ heap (not
gc).

Class C
1. Class C is a native type (because it does not use new language
constructs)
2. Class C is a unmanaged type (because it is not gc)
3. Class C code is X86 assembly code ran directly on the processor
4. Class C code is dynamically allocated the "new" on the regular C++ heap
(not gc).
Note the only difference in B and C is the type of code generated.
Note that Class B is unmanaged even though it occurs because the #pragma
unmanaged statement. That's a bit confusing. Do I have that concept correct?

It you have any other permutations of logic that would be helpful, I would
appreciate them.
As far as I know, even class A can be declared as a "normal" variable, i.e.
"A MyVar;", at which point normal C++ life cycle management takes place, even
if the actual object exists on the managed heap and the release of the raw
memory will be handled by the garbage collector. IMHO one of the great
advantages C++/CLI has over other .NET languages.

Lots of Greetings!
Volker
--
For email replies, please substitute the obvious.
Feb 5 '07 #2

"Joe" <ju**@junk.coma écrit dans le message de news:
3d**************************@KNOLOGY.NET...
>I am trying to get a good understanding of these concepts and how they
apply to code and classes (possibly different). As well as MSIL and Native
Code (x86 assembly).

To facilitate discussion consider the following code.

//////////////////////////////////////////////////
// compiled with /clr

ref class A {
//code and members
};
class B{
//code and members
};

#pragma unmanaged

class C{
//code and members
};

//////////////////////////////////////////////

Are the following comments correct?

Class A
1. Class A is a managed type (because it is gc)
2. Class A code is MSIL executed by the CLR
3. Class A is dynamically allocated with gcnew on the CLR heap (thus
garbage collected);

Class B
1. Class B is a native type (because it does not use new language
constructs)
2. Class B is a unmanaged type (because it is not gc)
3. Class B code is MSIL executed by the CLR
4. Class B is dynamically allocated with "new" on the regular C++ heap
(not gc).

Class C
1. Class C is a native type (because it does not use new language
constructs)
2. Class C is a unmanaged type (because it is not gc)
3. Class C code is X86 assembly code ran directly on the processor
4. Class C code is dynamically allocated the "new" on the regular C++ heap
(not gc).
Note the only difference in B and C is the type of code generated.
Note that Class B is unmanaged even though it occurs because the #pragma
unmanaged statement. That's a bit confusing. Do I have that concept
correct?

It you have any other permutations of logic that would be helpful, I would
appreciate them.
You're basically correct, but with a few precisions :
- B and C objects (native types) can also be allocated directly on the stack
or within aonther object. They do not necessraly are on the native heap.
- A objects can also be declared "on the stack" using the "A myobject;"
syntax. However, in this case, the object is really, physically, allocated
on the manegd heap. However, the compiler injects the necessary code so that
your code has the same semantic as with native types : ie, the object is
destroyed - that is, it's destructor is called - when the variable
"myobject" goes out of scope.

Arnaud
MVP - VC
Feb 6 '07 #3

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

Similar topics

4
by: Tim Menninger | last post by:
Just started working on this and have not found any real good resources out there. We have a lot of native C++ Dll code that we use for our app. We want to share the code so that C# ASP.net code...
4
by: William F. Kinsley | last post by:
My understanding is that when I re-compile a existing MFC application with the /clr switch, that the code generated is managed(with some exceptions) but that the data isn't, i.e. not garbage...
6
by: nicolas.hilaire | last post by:
Hi all, i'm not totally clear with some concepts about managed and unmanaged code. I'm asking myself some questions : - i've a MFC app, i want to use the framework dotnet by switching to...
5
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I have a class that is writen in unmanaged pure native C++. This class files (h and cpp) are inserted to a managed C++ (VC++ 2005, C++/CLI) DLL compoenet. This DLL compoenet is used in a C#...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.