IPinnable.cs 1.0 KB

12345678910111213141516171819202122232425
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. namespace System.Buffers
  5. {
  6. /// <summary>
  7. /// Provides a mechanism for pinning and unpinning objects to prevent the GC from moving them.
  8. /// </summary>
  9. public interface IPinnable
  10. {
  11. /// <summary>
  12. /// Call this method to indicate that the IPinnable object can not be moved by the garbage collector.
  13. /// The address of the pinned object can be taken.
  14. /// <param name="elementIndex">The offset to the element within the memory at which the returned <see cref="MemoryHandle"/> points to.</param>
  15. /// </summary>
  16. MemoryHandle Pin(int elementIndex);
  17. /// <summary>
  18. /// Call this method to indicate that the IPinnable object no longer needs to be pinned.
  19. /// The garbage collector is free to move the object now.
  20. /// </summary>
  21. void Unpin();
  22. }
  23. }