Exemplo n.º 1
0
        /// <summary>
        ///     Returns the address of the data of <paramref name="value"/>. If <typeparamref name="T" /> is a value type,
        ///     this will return <see cref="AddressOf{T}" />. If <typeparamref name="T" /> is a reference type,
        ///     this will return the equivalent of <see cref="AddressOfHeap{T}(T, OffsetOptions)" /> with
        ///     <see cref="OffsetOptions.FIELDS" />.
        /// </summary>
        public static Pointer <byte> AddressOfFields <T>(ref T value)
        {
            Pointer <T> addr = AddressOf(ref value);

            if (RuntimeInfo.IsStruct(value))
            {
                return(addr.Cast());
            }

            return(AddressOfHeapInternal(value, OffsetOptions.FIELDS));
        }
Exemplo n.º 2
0
        public static bool TryGetAddressOfHeap <T>(T value, OffsetOptions options, out Pointer <byte> ptr)
        {
            if (RuntimeInfo.IsStruct(value))
            {
                ptr = null;
                return(false);
            }

            ptr = AddressOfHeapInternal(value, options);
            return(true);
        }
Exemplo n.º 3
0
 public static void Destroy <T>(ref T value)
 {
     if (!RuntimeInfo.IsStruct(value))
     {
         int            size = Unsafe.SizeOf(value, SizeOfOptions.Data);
         Pointer <byte> ptr  = Unsafe.AddressOfFields(ref value);
         ptr.ClearBytes(size);
     }
     else
     {
         value = default;
     }
 }