PinnedSpan.cs 579 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;
  4. namespace Ryujinx.Graphics.GAL.Multithreading.Model
  5. {
  6. unsafe struct PinnedSpan<T> where T : unmanaged
  7. {
  8. private void* _ptr;
  9. private int _size;
  10. public PinnedSpan(ReadOnlySpan<T> span)
  11. {
  12. _ptr = Unsafe.AsPointer(ref MemoryMarshal.GetReference(span));
  13. _size = span.Length;
  14. }
  15. public ReadOnlySpan<T> Get()
  16. {
  17. return new ReadOnlySpan<T>(_ptr, _size * Unsafe.SizeOf<T>());
  18. }
  19. }
  20. }