Accessing unmanaged memory from managed code (withoutunsafe)

  • Thread starter Thread starter hml
  • Start date Start date
H

hml

Hi,

I have a "legacy" system (namely, vst audio plugins) which calls me through a mixed-mode, managed c++ library with a call similar to :

void process(float *input,int inputLength)

inside this method, I'm trying to find a way to instanciate a managed array (System.Single[]), which would map exactly to the portion of memory pointed by input, with a call like :

IntPtr pointer(&input[0]);
float myManagedArray[] = CreateArray(pointer,inputLength);

This would allow me to call a c# class from there, with the newly created array as parameter, fully managed, at low cost (no copy, realloc etc), and without having to go "unsafe" in the c# method (I'd like to avoid that).

Is there a way to do that ?

Any idea welcome, I'm using unsafe pointers to do that for the moment.

___
Newsgroups brought to you courtesy of www.dotnetjohn.com
 
No, there is no way to create a clr array on top of existing memory. All
memory the GC handles must be allocated by the GC in the current
architecture. Since this is a feature request that I have heard several
times already, you might want to search for a similar one on
http://lab.msdn.microsoft.com/productfeedback/
and add your vote and comment to it, or add the suggestion if there isn't
one like this yet.

Thanks.

Ronald Laeremans
Visual C++ team
 
Back
Top