Allocate reference type on native heap?

G

Guest

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
 
J

Jochen Kalmbach [MVP]

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
 

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