473,386 Members | 1,830 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.

Allocate reference type on native heap?

I apologize if this question has been asked before (I imagine it has). But,
I'd like a definitive response. Is it possible using C++/CLI to allocate a
(normally) managed reference type on the native heap?

That is, instead of using gcnew, and being subject to garabage collection,
could I use a native memory allocation routine like new(), with the result
being that the object is created on the native heap and not known by the
garbage collector? I would later deallocate storage myself. Everything I've
seen in scouring the web today suggests it can't be done (and it indeed
results in a compiler error when I try) but I thought I saw something at one
point that suggested it was possible...

Thanks,
Notre
May 10 '07 #1
1 1706
Hi Notre!
Is it possible using C++/CLI to allocate a
(normally) managed reference type on the native heap?
No.
You can allocate an object on the "stack" but not on a native heap.

The only thing you can do is to get an "GCHandle" from an allocated
object. Or you can "pin" an object and get the address from it.

But I don't know any why to *allocate* the object on an "hand-written-heap".

Of course... you can replace some of the memory-manager in the CLR...
(see IHostMemoryManager)

Greetings
Jochen
May 10 '07 #2

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

Similar topics

13
by: Abe Frohnman | last post by:
Hello all, I'm passing a reference to a class into the constructor of a form, like so: public MyForm(int count, ref Area myArea) {...} How can I use myArea outside the constructor? Should I...
15
by: Ian Lazarus | last post by:
Hello, If a function arg is a reference to a built in type, is it necessary for the function definition to specify whether the reference is to a managed or un-managed object? If so, does that...
4
by: Don Kim | last post by:
I have the following code: using namespace System; ref class R { public: R() {
3
by: Scott M. | last post by:
If I pass a reference type ByVal, am I making a copy of the object on the heap or am I making a copy of a pointer to the object on the heap? If I pass a string object (reference type) into a sub...
4
by: haitao.song | last post by:
Hi, As it is always stated that value type is allocated on stack, while reference types are on managed heap. How about the struct with string members? stuct A { string str; } String type is...
12
by: Sam Kong | last post by:
Hi, JavaScript hides its memory structure. I know that numbers, booleans, null and undefined are value types (value is directed saved in a variable). I want to know: - How JavaScript...
2
by: lovecreatesbea... | last post by:
If the built-in operator keyword new doesn't allocate memory on heap and it calls global operator new (::operator new) or class member operator new to do that. What are the two kinds of operator...
1
by: herman | last post by:
Hi, I have a static class attribute in my class: class A { public: static B aB; }
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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.