Quick way to go from double* to Double []

A

apm

Is there a way to go from a pointer to an unmanaged array of double to a
managed Array of Double without having to copy the values? The unmanaged
code calls back into managed code. The unmanaged callback arguments include
arrays of double. The delegate used to define the callback function requires
managed arguments.

The caller wants

void __cdecl func(double* x)

It actually needs to call

_delegate void func(Double x[])

Thanks in advance.

Regards,
DTC
 
C

Carl Daniel [VC++ MVP]

apm said:
Is there a way to go from a pointer to an unmanaged array of double to a
managed Array of Double without having to copy the values? The unmanaged
code calls back into managed code. The unmanaged callback arguments
include arrays of double. The delegate used to define the callback
function requires managed arguments.

The caller wants

void __cdecl func(double* x)

It actually needs to call

_delegate void func(Double x[])

You need to allocate the array in managed code in the first place, then you
can get a double __in* pointing into the managed array that can be passed to
your native code.

If the array must be allocated by native code, there's no way to reflect it
into the managed world as an array without copying the values, AFIAK
(although I do recall reading discussion of possibly adding such a facility
to the CLR, I don't think it was ever done).

-cd
 

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