frostfs-sdk-csharp/src/FrostFS.SDK.ClientV2/Tools/ClientEnvironment.cs
Pavel Gross 18126ea763 [#20] Optimize memory usage
Provide custom buffer and use ArrayPool

Signed-off-by: Pavel Gross <p.gross@yando.com>
2024-08-05 11:21:05 +03:00

47 lines
1.2 KiB
C#

using FrostFS.SDK.ModelsV2;
using Google.Protobuf;
using Grpc.Net.Client;
using System;
using System.Security.Cryptography;
using FrostFS.SDK.Cryptography;
using System.Buffers;
namespace FrostFS.SDK.ClientV2;
public class ClientEnvironment(Client client, ECDsa key, OwnerId owner, GrpcChannel channel, ModelsV2.Version version) : IDisposable
{
private ArrayPool<byte> _arrayPool;
internal OwnerId Owner { get; } = owner;
internal GrpcChannel Channel { get; private set; } = channel;
internal ModelsV2.Version Version { get; } = version;
internal NetworkSettings? NetworkSettings { get; set; }
internal Client Client { get; } = client;
internal ClientKey Key { get; } = new ClientKey(key);
/// <summary>
/// Custom pool is used for predefined sizes of buffers like grpc chunk
/// </summary>
internal ArrayPool<byte> GetArrayPool(int size)
{
_arrayPool ??= ArrayPool<byte>.Create(size, 256);
return _arrayPool;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
Channel.Dispose();
}
}
}