예제 #1
0
 internal static IntPtr RhHandleAlloc(Object value, GCHandleType type)
 {
     IntPtr h = RhpHandleAlloc(value, type);
     if (h == IntPtr.Zero)
         throw new OutOfMemoryException();
     return h;
 }
예제 #2
0
        /// <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);
            }
        }
예제 #3
0
파일: GCHandle.cs 프로젝트: Profit0004/mono
		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);
		}
예제 #4
0
        /// <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;
        }
예제 #5
0
파일: gchandle.cs 프로젝트: ArildF/masters
        // 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();
		}  
예제 #6
0
        // 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();
     }
 }
예제 #8
0
        [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();
        }  
예제 #9
0
 /// <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)));
     }
 }
예제 #10
0
파일: GCHandle.cs 프로젝트: mjp41/corert
        // 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();
        }
예제 #11
0
        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;
        }
예제 #12
0
	extern private static int GCAlloc(Object value, GCHandleType type);
예제 #13
0
 /// <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();
 }
예제 #14
0
 // 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);
 }
예제 #15
0
	// Private constructor that is called from "Alloc".
	private GCHandle(Object value, GCHandleType type)
			{
				handle = GCAlloc(value, type);
			}
예제 #16
0
 public void Alloc_InvalidGCHandleType_ThrowsArgumentOutOfRangeException(GCHandleType type)
 {
     AssertExtensions.Throws <ArgumentOutOfRangeException>("type", () => GCHandle.Alloc(new object(), type));
 }
예제 #17
0
 internal static extern IntPtr RhpHandleAlloc(object value, GCHandleType type);
예제 #18
0
 private static int GetTargetHandle(object obj, int handle, GCHandleType type)
 {
     throw new System.NotImplementedException();
 }
예제 #19
0
 public void Set(T obj, GCHandleType type = GCHandleType.Normal)
 {
     ptr = GCHandle.ToIntPtr(GCHandle.Alloc(obj, type));
 }
예제 #20
0
 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);
        }
예제 #22
0
 internal static extern IntPtr InternalAlloc(Object value, GCHandleType type);
예제 #23
0
 private static extern IntPtr InternalAlloc(object value, GCHandleType type);
예제 #24
0
 public SafeGCHandle(object target, GCHandleType type)
     : base(IntPtr.Zero, true)
 {
     SetHandle(GCHandle.ToIntPtr(GCHandle.Alloc(target, type)));
 }
예제 #25
0
 /// <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;
 }
예제 #27
0
 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);
 }
예제 #30
0
 /// <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;
 }
예제 #31
0
 public static IntPtr RhHandleAlloc(Object value, GCHandleType type)
 {
     return(RuntimeImports.RhHandleAlloc(value, type));
 }
예제 #32
0
 /// <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);
 }
예제 #33
0
    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();
        }
    }
예제 #34
0
 protected UvMemory(ILibuvTrace logger, GCHandleType handleType = GCHandleType.Weak) : base(IntPtr.Zero, true)
 {
     _log        = logger;
     _handleType = handleType;
 }
예제 #35
0
파일: GCHandle.cs 프로젝트: BeeINSIGHT/shim
 /// <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");
 }
예제 #36
0
 /// <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();
 }
예제 #37
0
	public static GCHandle Alloc(Object obj, GCHandleType type)
			{
				return new GCHandle(obj, type);
			}
예제 #38
0
파일: GCHandle.cs 프로젝트: Profit0004/mono
		public static System.Runtime.InteropServices.GCHandle Alloc(object value, GCHandleType type)
		{
			return new GCHandle (value,type);
		}
예제 #39
0
 private extern static int GetTargetHandle(object obj, int handle, GCHandleType type);
예제 #40
0
 /// <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));
 }
예제 #41
0
 /// <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);
 }
예제 #42
0
 [System.Security.SecurityCritical]  // auto-generated_required
 public static GCHandle Alloc(Object value, GCHandleType type)
 {
     return new GCHandle(value, type);
 }
예제 #43
0
파일: GCHandle.cs 프로젝트: Profit0004/mono
		private extern static int GetTargetHandle(object obj, int handle, GCHandleType type);
예제 #44
0
 public AutoFreeGCHandle(object targetObject, GCHandleType type = GCHandleType.Pinned)
 {
     _handle = GCHandle.Alloc(targetObject, type);
 }
예제 #45
0
        /// <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);
        }
예제 #46
0
 internal static extern IntPtr RhHandleAlloc(Object value, GCHandleType type);
예제 #47
0
 public static GCHandle Alloc(Object obj, GCHandleType gcht)
 {
     return GCHandle.Alloc(obj, gcht);
 }
예제 #48
0
 private extern static IntPtr GetGCHandle(RuntimeTypeHandle handle, GCHandleType type);
예제 #49
0
 public static System.Runtime.InteropServices.GCHandle Alloc(object value, GCHandleType type)
 {
     return(new GCHandle(value, type));
 }
예제 #50
0
        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);
		}
예제 #52
0
 private extern static IntPtr GetTargetHandle(object obj, IntPtr handle, GCHandleType type);
예제 #53
0
 public static GCHandle Alloc (object value, GCHandleType type) {
     throw new NotImplementedException();
 }
예제 #54
0
    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);
    }
예제 #55
0
 private static extern IntPtr RhpHandleAlloc(Object value, GCHandleType type);
예제 #56
0
        /// <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));
        }
예제 #57
0
 internal extern IntPtr GetGCHandle(GCHandleType type);
예제 #58
0
 public static GCHandle Alloc(object value, GCHandleType type)
 {
     GCRootedObjects.Track(value);
     return(new GCHandle(value, type));
 }
예제 #59
0
 [System.Security.SecurityCritical]  // auto-generated
 internal IntPtr GetGCHandle(GCHandleType type)
 {
     return GetGCHandle(GetNativeHandle(), type);
 }
예제 #60
0
 private static extern IntPtr RhpHandleAlloc(Object value, GCHandleType type);