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:
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.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?
精彩评论