Monday 15 March 2010

how to pass struct from c++ to c# with lowest latency? (without marshalling it?) -


Currently to distribute c # I from c ++ to both sides (c ++ and c #) Announce and use the representative. This approach is described. In my opinion, for low latency applications, this may not be suitable because the martial / unmarsharted CPU CPU / memory and when the structure size is large enough, the frequency of the request is sufficient and the latency requirement is quite high.

The scenario for such low latency, it will not be better to allocate additional memory, but works in C ++ memory directly with C # I have found that using a project System.IO.UnmanagedMemoryStream for and System.IO.BinaryReader , then some fields can be read for example in this way:

  Reader = New System. Io Binaryreader (stream); section. Position = 8; Return Reader Readin 32 ();   

However I can not find the full example (how is unmanagedMemoryStream in C # which indicates the structure or array of structures in c ++?) I'm not sure this is the best way, but what could you suggest for the transfer of C ++ to C # for "low latency" structures? Can you give an example?

I do not care about portability, maintenance etc. Only latency is important until I get rid of C # is a temporary solution.

Import your C ++ function and return it as a straight one parameter in C # , Use IntPtr type, and use

  DllImport ("somedll.dll") public static extern zero some functions (outside IntPtr someStructParameterOutput);   

and then:

  Intrp yourStruct; Some Functions (Outside Your Strut); Stream = new unmanaged memory line ((byte *) yourStruct.ToPointer (), length);    

No comments:

Post a Comment