Convert from managed byte[] to void* and back to byte[] again

J

jim.wiese

I've got a question which is hopefully a very simple one: I have an
unmanaged DLL which has abstracted the memory management such that I
can supply the malloc and free methods.

(ie)

void __nogc * pascal myMalloc (struct tag_MemoryStream __nogc * pX,
size_t cb) ;

void pascal myFree (void __nogc * pX, void *ptr) ;

.... I'd like to implement these methods such that I create and return a
managed array which is not GC'ed (ie GC::KeepAlive()) and returned,
then when myFree is called, I'd like to convert this back again (ie
GC::ReRegisterForFinalize( bytes )). Does anyone have an idea of how
to best go about this in managed C++?
 
M

Mattias Sjögren

Does anyone have an idea of how
to best go about this in managed C++?

You can use GCHandle to pin the array and retreive the pointer.
GC::KeepAlive and GC::ReRegisterForFinalize will not help you here.



Mattias
 

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