473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Instantiating Managed structs and classes not as handles

In the following example, where is "n" allocated (e.g. managed heap?) ?

public ref class N
{
....
....
}

main()
{
N^ n_handle; // allocated on managed heap

N n; // Where is this allocated? Not on native stack, right?
}

--
Greg McPherran
www.McPherran.com
Feb 18 '06 #1
3 1154
I read that it is automatically allocated on the managed and is a convenience
of C++. Also a destructor and !N() (finalize) methods should be defined for
any cleanup. The destructor can call the finalizer e.g. this->!()N so they
can both use the came code.

The idea is that the destructor will be called for cases of classes
instantiated as local variables (my original posted question) and the
finalizer is called by the GC for normal object instantiations via gcnew.
--
Greg McPherran
www.McPherran.com
"Greg" wrote:
In the following example, where is "n" allocated (e.g. managed heap?) ?

public ref class N
{
...
...
}

main()
{
N^ n_handle; // allocated on managed heap

N n; // Where is this allocated? Not on native stack, right?
}

--
Greg McPherran
www.McPherran.com

Feb 19 '06 #2
>I read that it is automatically allocated on the managed and is a
convenience
of C++. Also a destructor and !N() (finalize) methods should be defined
for
any cleanup. The destructor can call the finalizer e.g. this->!()N so they
can both use the came code.

The idea is that the destructor will be called for cases of classes
instantiated as local variables (my original posted question) and the
finalizer is called by the GC for normal object instantiations via gcnew.


both cases are allocated on the managed heap.
you should have a look at the thread 'Destructor: not guaranteed to be
called?' in this newsgroup, started on 31/01/2006.
It holds an extensive discussion about finalizers, destructors and the
difference between the 2.

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"
Feb 19 '06 #3
Greg schrieb:
main()
{
N^ n_handle; // allocated on managed heap

N n; // Where is this allocated? Not on native stack, right?
}


Both are allocated on the heap, but the "n" is deterministic calling the
destructor (~) of the class.
It is somehow similar to the "using" statement in C#...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Feb 19 '06 #4

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

Similar topics

4
by: CodeTyro | last post by:
My native language being C++, I've got a few questions that a couple of hours of searching on msdn didn't answer. First, when using unsafe code and pointers, what is the C# equivalent to the C++...
10
by: Edward Diener | last post by:
The documentation states the names of the various managed operators but does not give the signature for them. Is there some documentation which I have missed that gives the correct signature ? In...
3
by: Tommy Svensson \(InfoGrafix\) | last post by:
I've been instructed to work againt a huge unmanaged C++ API from a C# application. Now, the only way, as I've understood it, is to go the Managed Extensions for C++ way. This means I have to...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.