// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using System; using System.Runtime.InteropServices; namespace Microsoft.ML.OnnxRuntime { /// /// This class holds pre-packed weights of shared initializers to be shared across sessions using these initializers /// and thereby provide memory savings by sharing the same pre-packed versions of these shared initializers /// public class PrePackedWeightsContainer : SafeHandle { /// /// Constructs an empty PrePackedWeightsContainer /// public PrePackedWeightsContainer() : base(IntPtr.Zero, true) { NativeApiStatus.VerifySuccess(NativeMethods.OrtCreatePrepackedWeightsContainer(out handle)); } /// /// Internal accessor to call native methods /// internal IntPtr Pointer { get { return handle; } } /// /// Overrides SafeHandle.IsInvalid /// /// returns true if handle is equal to Zero public override bool IsInvalid { get { return handle == IntPtr.Zero; } } #region SafeHandle /// /// Overrides SafeHandle.ReleaseHandle() to deallocate /// a chunk of memory using the specified allocator. /// /// always returns true protected override bool ReleaseHandle() { NativeMethods.OrtReleasePrepackedWeightsContainer(handle); handle = IntPtr.Zero; return true; } #endregion } }