jcurl / RJCP.DLL.SerialPortStream

SerialPortStream is an independent implementation of System.IO.Ports.SerialPort and SerialStream for better reliability and maintainability. Default branch is 2.x and now has support for Mono with help of a C library.
Microsoft Public License
624 stars 197 forks source link

Reduce memory allocations created by List<WaitHandle>.ToArray() in OverlappedIoThreadMainLoop() #57

Closed Amarok79 closed 6 years ago

Amarok79 commented 6 years ago

In my usage scenario, I talk to a serial device quite often. Every 15-20 ms I send a short message and then receive a similar short message. While profiling my solution I noticed that about 11.000 bytes/sec were allocated from a single location in your library.

This PR adapts the existing OverlappedIoThreadMainLoop() to reuse pre-allocated WaitHandle[] instead of allocating a WaitHandle[] every loop.

jcurl commented 6 years ago

I've integrated my version, using a new datastructure based on your PR.