Beispiel #1
0
 private static void FreeInternal <T>(ref T obj)
     where T : class
 {
     Pool.PoolCollection <T> poolCollection = Pool.FindCollection <T>();
     if (poolCollection.ItemsInStack >= (long)((int)poolCollection.buffer.Length))
     {
         Pool.PoolCollection <T> itemsSpilled = poolCollection;
         itemsSpilled.ItemsSpilled = itemsSpilled.ItemsSpilled + (long)1;
         Pool.PoolCollection <T> itemsInUse = poolCollection;
         itemsInUse.ItemsInUse = itemsInUse.ItemsInUse - (long)1;
         obj = default(T);
         return;
     }
     poolCollection.buffer[checked ((IntPtr)poolCollection.ItemsInStack)] = obj;
     Pool.PoolCollection <T> itemsInStack = poolCollection;
     itemsInStack.ItemsInStack = itemsInStack.ItemsInStack + (long)1;
     Pool.PoolCollection <T> itemsInUse1 = poolCollection;
     itemsInUse1.ItemsInUse = itemsInUse1.ItemsInUse - (long)1;
     Pool.IPooled pooled = (object)obj as Pool.IPooled;
     if (pooled != null)
     {
         pooled.EnterPool();
     }
     obj = default(T);
 }
Beispiel #2
0
        public static T Get <T>()
            where T : class, new()
        {
            Pool.PoolCollection <T> poolCollection = Pool.FindCollection <T>();
            if (poolCollection.ItemsInStack <= (long)0)
            {
                Pool.PoolCollection <T> itemsCreated = poolCollection;
                itemsCreated.ItemsCreated = itemsCreated.ItemsCreated + (long)1;
                Pool.PoolCollection <T> itemsInUse = poolCollection;
                itemsInUse.ItemsInUse = itemsInUse.ItemsInUse + (long)1;
                return(Activator.CreateInstance <T>());
            }
            Pool.PoolCollection <T> itemsInStack = poolCollection;
            itemsInStack.ItemsInStack = itemsInStack.ItemsInStack - (long)1;
            Pool.PoolCollection <T> itemsInUse1 = poolCollection;
            itemsInUse1.ItemsInUse = itemsInUse1.ItemsInUse + (long)1;
            T t = poolCollection.buffer[checked ((IntPtr)poolCollection.ItemsInStack)];

            poolCollection.buffer[checked ((IntPtr)poolCollection.ItemsInStack)] = default(T);
            Pool.IPooled pooled = (object)t as Pool.IPooled;
            if (pooled != null)
            {
                pooled.LeavePool();
            }
            Pool.PoolCollection <T> itemsTaken = poolCollection;
            itemsTaken.ItemsTaken = itemsTaken.ItemsTaken + (long)1;
            return(t);
        }