/// <summary> /// Creates a new <see cref="IntPtrEx"/> from a <see cref="Byte"/> array. /// </summary> /// <remarks> /// Do not forget to free the <see cref="IntPtrEx"/>, using <see cref="IntPtrEx.Free()"/> method, /// after you've used it like this or you will create a memory leak. /// </remarks> /// <param name="array">The <see cref="Byte"/> array to use the memory location of.</param> public IntPtrEx(byte[] array) { m_Free = FreeParams.FreeHandle; m_Handle = GCHandle.Alloc(array, GCHandleType.Pinned); m_Pointer = m_Handle.AddrOfPinnedObject(); }
/// <summary> /// Creates a new <see cref="IntPtrEx"/> from a <see cref="Int64"/>. /// </summary> /// <param name="ptr">The memory location to use as pointer.</param> public IntPtrEx(long ptr) { m_Free = FreeParams.None; m_Handle = new GCHandle(); m_Pointer = new IntPtr(ptr); }
/// <summary> /// Creates a new <see cref="IntPtrEx"/> from a <see cref="String"/>. /// </summary> /// <remarks> /// Do not forget to free the <see cref="IntPtrEx"/>, using <see cref="IntPtrEx.Free()"/> method, /// after you've used it like this or you will create a memory leak. /// </remarks> /// <param name="str">The string to use the memory location of.</param> public IntPtrEx(string str) { m_Free = FreeParams.FreeHGlobal; m_Handle = new GCHandle(); m_Pointer = Marshal.StringToHGlobalAnsi(str); }
/// <summary> /// Creates a new <see cref="IntPtrEx"/> from a <see cref="IntPtr"/>. /// </summary> /// <param name="ptr">The <see cref="IntPtr"/> to use as base.</param> public IntPtrEx(IntPtr ptr) { m_Free = FreeParams.None; m_Handle = new GCHandle(); m_Pointer = ptr; }