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); }
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); }
public static void FillBuffer <T>(int count = 2147483647) where T : class, new() { Pool.PoolCollection <T> poolCollection = Pool.FindCollection <T>(); for (int i = 0; i < count && poolCollection.ItemsInStack < (long)((int)poolCollection.buffer.Length); i++) { poolCollection.buffer[checked ((IntPtr)poolCollection.ItemsInStack)] = Activator.CreateInstance <T>(); Pool.PoolCollection <T> itemsInStack = poolCollection; itemsInStack.ItemsInStack = itemsInStack.ItemsInStack + (long)1; } }
public static Pool.PoolCollection <T> FindCollection <T>() where T : class { Pool.PoolCollection <T> collection = Pool <T> .Collection; if (collection == null) { collection = new Pool.PoolCollection <T>(); Pool <T> .Collection = collection; Pool.directory.Add(typeof(T), Pool <T> .Collection); } return(collection); }