publicLongArray(long capacity) { if (_capacity < 0) thrownew ArgumentException("The capacity can not be negative"); _elementSize = SizeOf(default(T)); _capacity = capacity; _bytes = (ulong)capacity * (ulong)_elementSize; _head = AllocHGlobal((IntPtr)_bytes); }
public T this[long index] { get { IntPtr p = _getAddress(index); T val = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(p, typeof(T)); return val; } set { IntPtr p = _getAddress(index); StructureToPtr(value, p, true); } }
public IntPtr _getAddress(long index) { if (disposed) thrownew ObjectDisposedException("Can't access the array once it has been disposed!"); if (index < 0) thrownew IndexOutOfRangeException("Negative indices are not allowed"); if (!(index < _capacity)) thrownew IndexOutOfRangeException("Index is out of bounds of this array"); return (IntPtr)((ulong)_head + (ulong)index * (ulong)(_elementSize)); } }