mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2026-02-04 07:42:53 +00:00
Use ArrayPool as a write buffer
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics;
|
using System.Buffers;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
@@ -20,6 +21,7 @@ public class Sharp7Plc : IPlc
|
|||||||
private readonly CacheVariableNameParser variableNameParser = new CacheVariableNameParser(new VariableNameParser());
|
private readonly CacheVariableNameParser variableNameParser = new CacheVariableNameParser(new VariableNameParser());
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
private Sharp7Connector s7Connector;
|
private Sharp7Connector s7Connector;
|
||||||
|
private static readonly ArrayPool<byte> arrayPool = ArrayPool<byte>.Shared;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -159,11 +161,17 @@ public class Sharp7Plc : IPlc
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Use ArrayPool.Rent() once we drop Framwework support
|
var buffer = arrayPool.Rent(address.BufferLength);
|
||||||
var bytes = new byte[address.BufferLength];
|
try
|
||||||
ValueConverter.WriteToBuffer(bytes, value, address);
|
{
|
||||||
|
ValueConverter.WriteToBuffer(buffer, value, address);
|
||||||
|
|
||||||
await s7Connector.WriteBytes(address.Operand, address.Start, bytes, address.DbNo, token);
|
await s7Connector.WriteBytes(address.Operand, address.Start, buffer, address.DbNo, token);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ArrayPool<Byte>.Shared.Return(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user