public static IlInstanceHolderPoolItem Alloc(Type type, object value = null)
        {
            lock (TypePools)
            {
                if (!TypePools.ContainsKey(type))
                {
                    TypePools[type] = new List <IlInstanceHolderPool>();
                }
                var poolsType = TypePools[type];
                var freePool  = poolsType.FirstOrDefault(pool => pool.HasAvailable);
                if (freePool == null)
                {
                    var nextPoolSize = 1 << (poolsType.Count + 2);
                    //if (NextPoolSize < 2048) NextPoolSize = 2048;

#if DEBUG_ILINSTANCEHOLDERPOOL_TIME
                    Console.BackgroundColor = ConsoleColor.DarkRed;
                    Console.Error.Write("Create ILInstanceHolderPool({0})[{1}]...", Type, NextPoolSize);
                    var Start = DateTime.UtcNow;
#endif
                    poolsType.Add(freePool = new IlInstanceHolderPool(type, nextPoolSize));
#if DEBUG_ILINSTANCEHOLDERPOOL_TIME
                    var End = DateTime.UtcNow;
                    Console.Error.WriteLine("Ok({0})", End - Start);
                    Console.ResetColor();
#endif
                }
                var item = freePool.Alloc();
                item.Value = value;
                return(item);
            }
        }
Exemplo n.º 2
0
 public IlInstanceHolderPoolItem(IlInstanceHolderPool parent, int index, FieldInfo fieldInfo)
 {
     _parent   = parent;
     Index     = index;
     FieldInfo = fieldInfo;
 }