开发者

Best practice of sending array from native code to managed code(C++/CLI)?

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 nat开发者_运维问答ive world.

Thanks.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜