You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

33 lines
642 B

  1. using System;
  2. using System.Buffers;
  3. namespace MQTTnet.AspNetCore.Tests.Mockups
  4. {
  5. public class MemoryOwner : IMemoryOwner<byte>
  6. {
  7. private readonly byte[] _raw;
  8. public MemoryOwner(int size)
  9. {
  10. if (size <= 0)
  11. {
  12. size = 1024;
  13. }
  14. if (size > 4096)
  15. {
  16. size = 4096;
  17. }
  18. _raw = ArrayPool<byte>.Shared.Rent(size);
  19. Memory = _raw;
  20. }
  21. public void Dispose()
  22. {
  23. ArrayPool<byte>.Shared.Return(_raw);
  24. }
  25. public Memory<byte> Memory { get; }
  26. }
  27. }