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

  • Thread starter Thread starter jim.wiese
  • Start date Start date
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++?
 
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
 
Back
Top