Sunday, 15 August 2010

c# - Using managed memory for Registered I/O RIOSend function call -



c# - Using managed memory for Registered I/O RIOSend function call -

i'm working on scheme needs high speed, low latency/jitter communication , it's written in c#. saw there new mechanism improve performance sockets called windows registered io http://www.serverframework.com/asynchronousevents/2011/10/windows-8-registered-io-networking-extensions.html

...but not available c# @ moment ...and seems show improve performance based on testing in c++.

anyway, i've written managed c++/cli part create dll, , seems work fine c# , much improved numbers.

but i'm wondering if can save buffer re-create sending...

currently c++ wrapper looks this:

bool managedsenddata( array<byte> ^ buf, ulong buflen ) { // must pin array memory until we're done sending it, // @ point it'll copied unmanaged memory pin_ptr<byte> p = &buf[0]; // pinning 1 element of array pins whole array unsigned char * cp = p; homecoming _riobs->senddata( cp, buflen ); }

where _riobs unmanaged c++ object implements registered i/o functionality. in function, re-create info buffer registered @ startup rioregisterbuffer(), , phone call riosend() notify os there info send.

so, question can have user of managed c++ object pass in managed byte array on startup , phone call gchandle::alloc() on prepare in place , prevent garbage collection, phone call rioregisterbuffer() on in managed application, , utilize while managed c++ object alive? register managed buffer memory instead of unmanaged memory, , when user wants send data, fill buffer have reference to, , notify me how many bytes want send. it's blocking send , waits completion event, wouldn't using buffer 1 time again until os done it's thing data.

it seems work long unmanaged applications can utilize managed or unmanaged memory interchangeably long managed memory locked downwards until it's not longer needed.

you can phone call rio straight c# rather going via c++/cli; allocate big buffer > 85k move loh rather interfering regular gc , can utilize similar suggesting:

_underlyingbuffer = new byte[bufferlength]; var pinnedbuffer = gchandle.alloc(_underlyingbuffer, gchandletype.pinned); var address = marshal.unsafeaddrofpinnedarrayelement(_underlyingbuffer, 0); var bufferid = _rio.registerbuffer(address, bufferlength);

i've set sample http echo server using direct interop registered io , some analysis of how performs (very well).

c# sockets c++-cli

No comments:

Post a Comment