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:

  1. server c# side pass pointer client c++ side.
  2. at c++ side read , process struct received pointer.
  3. 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

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -