internal static IntPtr RhHandleAlloc(Object value, GCHandleType type) { IntPtr h = RhpHandleAlloc(value, type); if (h == IntPtr.Zero) throw new OutOfMemoryException(); return h; }
/// <summary> /// 指定したオブジェクトに指定した型のハンドルを割り当てます /// </summary> /// <param name="value">GCの対象からはずすオブジェクト</param> /// <param name="type">作成する System.Runtime.InteropServices.GCHandle の型を示す、System.Runtime.InteropServices.GCHandleType 値の 1 つ</param> #else /// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="type"></param> #endif public ScopedGCHandle(object value, GCHandleType type) { if (value != null) { this.Handle = GCHandle.Alloc(value, type); } }
internal GCHandle(object value, GCHandleType type) { // MS does not crash/throw on (most) invalid GCHandleType values (except -1) if ((type < GCHandleType.Weak) || (type > GCHandleType.Pinned)) type = GCHandleType.Normal; handle = GetTargetHandle (value, 0, type); }
/// <summary> /// 指定したオブジェクトに指定した型のハンドルを割り当てます /// </summary> /// <param name="value">GCの対象からはずすオブジェクト</param> /// <param name="type">作成する System.Runtime.InteropServices.GCHandle の型を示す、System.Runtime.InteropServices.GCHandleType 値の 1 つ</param> #else /// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="type"></param> #endif public ScopedGCHandle(object value, GCHandleType type) { if (value != null) { handle = GCHandle.Alloc(value, type); } disposed = false; }
// Allocate a handle storing the object and the type. internal GCHandle(Object value, GCHandleType type) { m_handle = InternalAlloc(value, type); // Record if the handle is pinned. if (type == GCHandleType.Pinned) SetIsPinned(); }
// Allocate a handle storing the object and the type. private UnsafeGCHandle(Object value, GCHandleType type) { Debug.Assert((uint)type <= (uint)GCHandleType.Normal, "unexpected handle type"); _handle = InternalCalls.RhpHandleAlloc(value, type); if (_handle == IntPtr.Zero) throw new OutOfMemoryException(); }
internal GCHandle(object value, GCHandleType type) { if (type > GCHandleType.Pinned) { throw new ArgumentOutOfRangeException("type", Environment.GetResourceString("ArgumentOutOfRange_Enum")); } this.m_handle = InternalAlloc(value, type); if (type == GCHandleType.Pinned) { this.SetIsPinned(); } }
[System.Security.SecurityCritical] // auto-generated internal GCHandle(Object value, GCHandleType type) { // Make sure the type parameter is within the valid range for the enum. if ((uint)type > (uint)MaxHandleType) throw new ArgumentOutOfRangeException("type", Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.EndContractBlock(); m_handle = InternalAlloc(value, type); // Record if the handle is pinned. if (type == GCHandleType.Pinned) SetIsPinned(); }
/// <summary> /// Initializes a new instance of the <see cref="SafeGCHandle"/> class referring to the target in the given way. /// </summary> /// <param name="target">The object to reference.</param> /// <param name="type">The way to reference the object.</param> public SafeGCHandle(object target, GCHandleType type) : base(IntPtr.Zero, true) { RuntimeHelpers.PrepareConstrainedRegions(); try { // The StyleCop warning for this try block is incorrect; it is required to create a Constrained Execution Region } finally { this.SetHandle(GCHandle.ToIntPtr(GCHandle.Alloc(target, type))); } }
// Allocate a handle storing the object and the type. internal GCHandle(Object value, GCHandleType type) { // Make sure the type parameter is within the valid range for the enum. if ((uint)type > (uint)MaxHandleType) { throw new ArgumentOutOfRangeException(); // "type", SR.ArgumentOutOfRange_Enum; } if (type == GCHandleType.Pinned) GCHandleValidatePinnedObject(value); _handle = RuntimeImports.RhHandleAlloc(value, type); // Record if the handle is pinned. if (type == GCHandleType.Pinned) SetIsPinned(); }
public static IntPtr RhHandleAlloc(object value, GCHandleType type) { IntPtr h = InternalCalls.RhpHandleAlloc(value, type); if (h == IntPtr.Zero) { // Throw the out of memory exception defined by the classlib, using the return address of this method // to find the correct classlib. ExceptionIDs exID = ExceptionIDs.OutOfMemory; IntPtr returnAddr = BinderIntrinsics.GetReturnAddress(); Exception e = EH.GetClasslibException(exID, returnAddr); throw e; } return h; }
extern private static int GCAlloc(Object value, GCHandleType type);
/// <summary> /// Инициализирует новый экземпляр класса <see cref="DisposableHandle"/> /// </summary> /// <param name="value">Объект, для которого выполняется выделение дескриптора</param> /// <param name="handleType">Значение перечисления <see cref="GCHandleType"/>, определяющее тип выделяемого дескриптора</param> private DisposableHandle(object value, GCHandleType handleType) { InnerHandle = GCHandle.Alloc(value, handleType); Pointer = InnerHandle.AddrOfPinnedObject(); }
// Allocate a handle storing the object and the type. private UnsafeGCHandle(Object value, GCHandleType type) { Debug.Assert((uint)type <= (uint)MaxHandleType, "Unexpected handle type"); _handle = RuntimeImports.RhHandleAlloc(value, type); }
// Private constructor that is called from "Alloc". private GCHandle(Object value, GCHandleType type) { handle = GCAlloc(value, type); }
public void Alloc_InvalidGCHandleType_ThrowsArgumentOutOfRangeException(GCHandleType type) { AssertExtensions.Throws <ArgumentOutOfRangeException>("type", () => GCHandle.Alloc(new object(), type)); }
internal static extern IntPtr RhpHandleAlloc(object value, GCHandleType type);
private static int GetTargetHandle(object obj, int handle, GCHandleType type) { throw new System.NotImplementedException(); }
public void Set(T obj, GCHandleType type = GCHandleType.Normal) { ptr = GCHandle.ToIntPtr(GCHandle.Alloc(obj, type)); }
public static GCHandle Alloc(Object value, GCHandleType type) { return(new GCHandle(value, type)); }
/// <summary> /// Creates a new WeakHashSet of references to the contents of the collection /// </summary> /// <param name="collection">The collection holding the items to reference</param> /// <param name="comparer">The comparer to use for items</param> /// <param name="handleType">The type of GCHandle to use</param> public WeakHashSet(IEnumerable <T> collection, IEqualityComparer <T>?comparer, GCHandleType handleType) { if (collection is null) { throw new ArgumentNullException(nameof(collection), "Collection cannot be null"); } Comparer = comparer ?? EqualityComparer <T> .Default; _HandleType = handleType; _Values = collection.Select(item => new SetItem(item, this)).ToArray(); _Size = _Values.Length; Array.Sort(_Values, Comparer <SetItem> .Default); }
internal static extern IntPtr InternalAlloc(Object value, GCHandleType type);
private static extern IntPtr InternalAlloc(object value, GCHandleType type);
public SafeGCHandle(object target, GCHandleType type) : base(IntPtr.Zero, true) { SetHandle(GCHandle.ToIntPtr(GCHandle.Alloc(target, type))); }
/// <summary> /// Creates a new GC Reference /// </summary> /// <param name="target">The target object</param> /// <param name="handleType">The type of GC Handle</param> public GCReference(object target, GCHandleType handleType) { _Handle = GCHandle.Alloc(target, handleType); }
/// <summary> /// Creates a new WeakDictionary with the given equality comparer /// </summary> /// <param name="comparer">The equality comparer to use when comparing keys</param> /// <param name="handleType">The type of GCHandle to use</param> public WeakDictionary(IEqualityComparer <TKey> comparer, GCHandleType handleType) { _Dictionary = new Dictionary <TKey, GCReference>(comparer); _HandleType = handleType; }
public static GCHandle Alloc(Object obj, GCHandleType gcht) { return(GCHandle.Alloc(obj, gcht)); }
/// <summary> /// Creates a new WeakDictionary of references to the contents of the collection with the given equality comparer /// </summary> /// <param name="collection">The collection holding the key/value pairs to add</param> /// <param name="comparer">The equality comparer to use when comparing keys</param> /// <param name="handleType">The type of GCHandle to use</param> public WeakDictionary(IEnumerable <KeyValuePair <TKey, TValue> > collection, IEqualityComparer <TKey> comparer, GCHandleType handleType) { _HandleType = handleType; _Dictionary = collection.ToDictionary((value) => value.Key, (value) => new GCReference(value.Value, _HandleType), comparer); }
public DisposableGCHandle(object o, GCHandleType type) { _handle = GCHandle.Alloc(o, type); }
/// <summary> /// Wraps the provided object with a <see cref="GCHandle" />, using the given <see cref="GCHandleType" />. /// </summary> /// <param name="target">The target object to wrap.</param> /// <param name="handleType">The handle type to use.</param> public ObjectHandle(T target, GCHandleType handleType) { handle = GCHandle.Alloc(target, handleType); fromPointer = false; }
public static IntPtr RhHandleAlloc(Object value, GCHandleType type) { return(RuntimeImports.RhHandleAlloc(value, type)); }
/// <summary> /// Constructs an instance of the GCHandleKeeper class. /// </summary> /// <param name="val"></param> /// <param name="type"></param> public GCHandleKeeper(object val, GCHandleType type) { this.GCHandle = GCHandle.Alloc(val, type); }
public void AllocTest(GCHandleType gcht) { for (long i = 0; i < m_numIters; i++) { m_gchArray[0] = GCHandle.Alloc(m_objectArray[0], gcht); m_gchArray[1] = GCHandle.Alloc(m_objectArray[1], gcht); m_gchArray[2] = GCHandle.Alloc(m_objectArray[2], gcht); m_gchArray[3] = GCHandle.Alloc(m_objectArray[3], gcht); m_gchArray[4] = GCHandle.Alloc(m_objectArray[4], gcht); m_gchArray[5] = GCHandle.Alloc(m_objectArray[5], gcht); m_gchArray[6] = GCHandle.Alloc(m_objectArray[6], gcht); m_gchArray[7] = GCHandle.Alloc(m_objectArray[7], gcht); m_gchArray[8] = GCHandle.Alloc(m_objectArray[8], gcht); m_gchArray[9] = GCHandle.Alloc(m_objectArray[9], gcht); m_gchArray[10] = GCHandle.Alloc(m_objectArray[10], gcht); m_gchArray[11] = GCHandle.Alloc(m_objectArray[11], gcht); m_gchArray[12] = GCHandle.Alloc(m_objectArray[12], gcht); m_gchArray[13] = GCHandle.Alloc(m_objectArray[13], gcht); m_gchArray[14] = GCHandle.Alloc(m_objectArray[14], gcht); m_gchArray[15] = GCHandle.Alloc(m_objectArray[15], gcht); m_gchArray[16] = GCHandle.Alloc(m_objectArray[16], gcht); m_gchArray[17] = GCHandle.Alloc(m_objectArray[17], gcht); m_gchArray[18] = GCHandle.Alloc(m_objectArray[18], gcht); m_gchArray[19] = GCHandle.Alloc(m_objectArray[19], gcht); m_gchArray[20] = GCHandle.Alloc(m_objectArray[20], gcht); m_gchArray[21] = GCHandle.Alloc(m_objectArray[21], gcht); m_gchArray[22] = GCHandle.Alloc(m_objectArray[22], gcht); m_gchArray[23] = GCHandle.Alloc(m_objectArray[23], gcht); m_gchArray[24] = GCHandle.Alloc(m_objectArray[24], gcht); m_gchArray[25] = GCHandle.Alloc(m_objectArray[25], gcht); m_gchArray[26] = GCHandle.Alloc(m_objectArray[26], gcht); m_gchArray[27] = GCHandle.Alloc(m_objectArray[27], gcht); m_gchArray[28] = GCHandle.Alloc(m_objectArray[28], gcht); m_gchArray[29] = GCHandle.Alloc(m_objectArray[29], gcht); m_gchArray[30] = GCHandle.Alloc(m_objectArray[30], gcht); m_gchArray[31] = GCHandle.Alloc(m_objectArray[31], gcht); m_gchArray[32] = GCHandle.Alloc(m_objectArray[32], gcht); m_gchArray[33] = GCHandle.Alloc(m_objectArray[33], gcht); m_gchArray[34] = GCHandle.Alloc(m_objectArray[34], gcht); m_gchArray[35] = GCHandle.Alloc(m_objectArray[35], gcht); m_gchArray[36] = GCHandle.Alloc(m_objectArray[36], gcht); m_gchArray[37] = GCHandle.Alloc(m_objectArray[37], gcht); m_gchArray[38] = GCHandle.Alloc(m_objectArray[38], gcht); m_gchArray[39] = GCHandle.Alloc(m_objectArray[39], gcht); m_gchArray[40] = GCHandle.Alloc(m_objectArray[40], gcht); m_gchArray[41] = GCHandle.Alloc(m_objectArray[41], gcht); m_gchArray[42] = GCHandle.Alloc(m_objectArray[42], gcht); m_gchArray[43] = GCHandle.Alloc(m_objectArray[43], gcht); m_gchArray[44] = GCHandle.Alloc(m_objectArray[44], gcht); m_gchArray[45] = GCHandle.Alloc(m_objectArray[45], gcht); m_gchArray[46] = GCHandle.Alloc(m_objectArray[46], gcht); m_gchArray[47] = GCHandle.Alloc(m_objectArray[47], gcht); m_gchArray[48] = GCHandle.Alloc(m_objectArray[48], gcht); m_gchArray[49] = GCHandle.Alloc(m_objectArray[49], gcht); for (int j = 0; j < m_gchArray.Length; j++) { m_gchArray[j].Free(); } GC.Collect(); } }
protected UvMemory(ILibuvTrace logger, GCHandleType handleType = GCHandleType.Weak) : base(IntPtr.Zero, true) { _log = logger; _handleType = handleType; }
/// <include file='../../_Doc/mscorlib.xml' path='doc/members/member[@name="M:System.Runtime.InteropServices.GCHandle.Alloc(System.Object,System.Runtime.InteropServices.GCHandleType)"]/*' /> public static GCHandle Alloc(object value, GCHandleType type) { throw new PlatformNotSupportedException("PCL"); }
public static GCHandle Alloc(Object obj, GCHandleType type) { return new GCHandle(obj, type); }
public static System.Runtime.InteropServices.GCHandle Alloc(object value, GCHandleType type) { return new GCHandle (value,type); }
private extern static int GetTargetHandle(object obj, int handle, GCHandleType type);
/// <summary> /// Выделяет дескриптор указанного типа для указанного объекта /// </summary> /// <param name="value">Объект, для которого выполняется выделение дескриптора</param> /// <param name="handleType">Значение перечисления <see cref="GCHandleType"/>, определяющее тип выделяемого дескриптора</param> /// <returns>Выделенный дескриптор <see cref="DisposableHandle"/> для указанного объекта</returns> public static DisposableHandle Alloc(object value, GCHandleType handleType = GCHandleType.Pinned) { return(new DisposableHandle(value, handleType)); }
/// <summary> /// Выделяет дескриптор указанного типа для указанного объекта /// </summary> /// <param name="value">Объект, для которого выполняется выделение дескриптора</param> /// <param name="handleType">Значение перечисления <see cref="GCHandleType"/>, определяющее тип выделяемого дескриптора</param> /// <returns>Выделенный дескриптор <see cref="DisposableHandle"/> для указанного объекта</returns> public static DisposableHandle Alloc(object value, GCHandleType handleType = GCHandleType.Pinned) { return new DisposableHandle(value, handleType); }
[System.Security.SecurityCritical] // auto-generated_required public static GCHandle Alloc(Object value, GCHandleType type) { return new GCHandle(value, type); }
public AutoFreeGCHandle(object targetObject, GCHandleType type = GCHandleType.Pinned) { _handle = GCHandle.Alloc(targetObject, type); }
/// <summary> /// 指定したオブジェクトに指定した型のハンドルを割り当てます /// </summary> /// <param name="value">System.Runtime.InteropServices.GCHandle を使用するオブジェクト</param> /// <param name="type">作成する System.Runtime.InteropServices.GCHandle の型を示す、System.Runtime.InteropServices.GCHandleType 値の 1 つ</param> /// <returns>オブジェクトをガベージ コレクションから保護する新しい System.Runtime.InteropServices.GCHandle。 /// System.Runtime.InteropServices.GCHandle は、不要になったときに System.Runtime.InteropServices.GCHandle.Free() で解放する必要があります。</returns> /// <exception cref="System.ArgumentException">非プリミティブ (blittable でない) メンバを持つインスタンスは固定できません</exception> #else /// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="type"></param> /// <returns></returns> #endif public static ScopedGCHandle Alloc(object value, GCHandleType type) { return new ScopedGCHandle(value, type); }
internal static extern IntPtr RhHandleAlloc(Object value, GCHandleType type);
public static GCHandle Alloc(Object obj, GCHandleType gcht) { return GCHandle.Alloc(obj, gcht); }
private extern static IntPtr GetGCHandle(RuntimeTypeHandle handle, GCHandleType type);
public static System.Runtime.InteropServices.GCHandle Alloc(object value, GCHandleType type) { return(new GCHandle(value, type)); }
public static void Alloc_Type_ReturnsExpected(object value, GCHandleType type) { GCHandle handle = GCHandle.Alloc(value, type); ValidateGCHandle(handle, type, value); }
internal IntPtr GetGCHandle(GCHandleType type) { return RuntimeTypeHandle.GetGCHandle(this.GetNativeHandle(), type); }
private extern static IntPtr GetTargetHandle(object obj, IntPtr handle, GCHandleType type);
public static GCHandle Alloc (object value, GCHandleType type) { throw new NotImplementedException(); }
public static int Main(string[] args) { int size = 10000; int power = 20; int numIterations = 0; GCHandle[] list = new GCHandle[size]; if (args.Length == 0) { //using defaults numIterations = 100; } else if (args.Length == 1) { if (!Int32.TryParse(args[0], out numIterations)) { Usage(); return(1); } } else { Usage(); return(1); } Console.WriteLine("Running {0} iterations", numIterations); for (int j = 0; j < numIterations; j++) { for (int i = 0; i < size; i++) { GCHandleType type = GCHandleType.Normal; if (i % 5 == 0) { // pin every 5th handle type = GCHandleType.Pinned; } if (!list[i].IsAllocated) { try { byte[] b = new byte[(int)Math.Pow(2, (i % power))]; list[i] = (GCHandle.Alloc(b, type)); } catch (OutOfMemoryException) { Console.WriteLine("OOM"); Console.WriteLine("Heap size: {0}", GC.GetTotalMemory(false)); Console.WriteLine("Trying to allocate array of size: {0}", Math.Pow(2, (i % power))); } } else { list[i].Free(); } } } return(100); }
private static extern IntPtr RhpHandleAlloc(Object value, GCHandleType type);
/// <summary> /// 指定したオブジェクトに指定した型のハンドルを割り当てます /// </summary> /// <param name="value">System.Runtime.InteropServices.GCHandle を使用するオブジェクト</param> /// <param name="type">作成する System.Runtime.InteropServices.GCHandle の型を示す、System.Runtime.InteropServices.GCHandleType 値の 1 つ</param> /// <returns>オブジェクトをガベージ コレクションから保護する新しい System.Runtime.InteropServices.GCHandle。 /// System.Runtime.InteropServices.GCHandle は、不要になったときに System.Runtime.InteropServices.GCHandle.Free() で解放する必要があります。</returns> /// <exception cref="System.ArgumentException">非プリミティブ (blittable でない) メンバを持つインスタンスは固定できません</exception> #else /// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="type"></param> /// <returns></returns> #endif public static ScopedGCHandle Alloc(object value, GCHandleType type) { return(new ScopedGCHandle(value, type)); }
internal extern IntPtr GetGCHandle(GCHandleType type);
public static GCHandle Alloc(object value, GCHandleType type) { GCRootedObjects.Track(value); return(new GCHandle(value, type)); }
[System.Security.SecurityCritical] // auto-generated internal IntPtr GetGCHandle(GCHandleType type) { return GetGCHandle(GetNativeHandle(), type); }