how to pass data from c# to c++ (just pointer, no marshalling) -
my application contains 2 sides - client side on c++ , server side on c#. need client side receive structure lowest possible latency. want receive pointer structure , avoid marshaling. structure that:
struct orderaction { orderactiontype actiontype; uint userid; int ordersexecutorid; int instrumentid; int strategyid; ....
so think want this:
- server c# side pass pointer client c++ side.
- at c++ side read , process struct received pointer.
- at c# side free resources (delete struct) if needed.
in future plan replace c# server side c++ server side want client independent. client shouldn't know called , used c#.
questions:
- should use algorithm?
- if @ step 1 should allocate structure @ managed memory or unmanaged memory?
- what methods should use , can link example?
you'll first need double check struct blittable. if struct not blittable cannot avoid marshalling of form. stands, struct in question looks blittable, given fields have shown, , assuming orderactiontype
enum
.
then need pass struct ref , pinned, , pinned address passed native code.
on c++ side code this:
int __stdcall foo(orderaction *orderaction) { .... }
on c# side looks this:
[dllimport(@"mylib.dll")] static extern int foo(ref orderaction orderaction);
Comments
Post a Comment