using System.Runtime.InteropServices; #pragma warning disable 1591 // ReSharper disable InconsistentNaming namespace OpenCvSharp.Internal.Util; /// /// /// /// public class ArrayAddress1 : DisposableObject where T : unmanaged { private readonly Array array; private GCHandle gch; public ArrayAddress1(T[] array) { this.array = array ?? throw new ArgumentNullException(nameof(array)); gch = GCHandle.Alloc(array, GCHandleType.Pinned); } public ArrayAddress1(IEnumerable enumerable) : this(enumerable.ToArray()) { } public ArrayAddress1(T[,] array) { this.array = array ?? throw new ArgumentNullException(nameof(array)); gch = GCHandle.Alloc(array, GCHandleType.Pinned); } /// /// Releases unmanaged resources /// protected override void DisposeUnmanaged() { if (gch.IsAllocated) { gch.Free(); } base.DisposeUnmanaged(); } public IntPtr Pointer => gch.AddrOfPinnedObject(); public int Length => array.Length; }