views:

51

answers:

1

I'm writing a win32 dll for read/write USB HID device. The data for exchange is a 64 byte unsigned char array. The client program is written in C++/CLI.

In order to achieve max speed and minimum overhead, I need an efficient way to sending the array to managed client.

There are two options I can think of right now:

  1. Native: use PostMessage and send the pointer for the array.
    Managed: in WndProc, Marshal.Copy the pointer to a new managed Byte array, then delete the pointer.

  2. Native: use function pointer as a callback to process the data.
    Managed: use Marshal.GetFunctionPointerForDelegate to pass function pointer to native world.

Thanks.

+2  A: 

I would say choosing bizarre ways of marshalling is premature optimization. Use the most simple way to marshal the data, and try to evaluate other methods if that doesn't perform satisfactorily. Barring any architectural need for callbacks or message posting, why not just pass the array to a function?

Reinderien