From 1c869647abd10e5a25e5a87042f4811b3e790f1c Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Tue, 2 Jul 2019 02:06:32 -0500 Subject: [PATCH] Use pre-allocated buffer in UDP server --- DS4Windows/DS4Control/ControlService.cs | 10 ++++++++-- DS4Windows/DS4Control/UdpServer.cs | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 8cd04d8..19631d5 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -58,6 +58,12 @@ namespace DS4Windows } private X360Data[] processingData = new X360Data[4]; + private byte[][] udpOutBuffers = new byte[4][] + { + new byte[100], new byte[100], + new byte[100], new byte[100] + }; + void GetPadDetailForIdx(int padIdx, ref DualShockPadMeta meta) { @@ -474,7 +480,7 @@ namespace DS4Windows { DualShockPadMeta padDetail = new DualShockPadMeta(); GetPadDetailForIdx(tempIdx, ref padDetail); - _udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]); + _udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx], udpOutBuffers[tempIdx]); }; device.MotionEvent = tempEvnt; @@ -696,7 +702,7 @@ namespace DS4Windows { DualShockPadMeta padDetail = new DualShockPadMeta(); GetPadDetailForIdx(tempIdx, ref padDetail); - _udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]); + _udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx], udpOutBuffers[tempIdx]); }; device.MotionEvent = tempEvnt; diff --git a/DS4Windows/DS4Control/UdpServer.cs b/DS4Windows/DS4Control/UdpServer.cs index 90a4fa4..f1b56a0 100644 --- a/DS4Windows/DS4Control/UdpServer.cs +++ b/DS4Windows/DS4Control/UdpServer.cs @@ -581,7 +581,7 @@ namespace DS4Windows return true; } - public void NewReportIncoming(ref DualShockPadMeta padMeta, DS4State hidReport) + public void NewReportIncoming(ref DualShockPadMeta padMeta, DS4State hidReport, byte[] outputData) { if (!running) return; @@ -647,7 +647,7 @@ namespace DS4Windows unchecked { - byte[] outputData = new byte[100]; + //byte[] outputData = new byte[100]; int outIdx = BeginPacket(outputData, 1001); Array.Copy(BitConverter.GetBytes((uint)MessageType.DSUS_PadDataRsp), 0, outputData, outIdx, 4); outIdx += 4;