public CustomAllocatedObjectPool(AllocateDelegate allocate, FreeDelegate free, int initialSize, int maxItems) { Assert.IsNotNull(allocate); allocateDelegate = allocate; freeDelegate = free; this.free = new Stack <T>(initialSize); this.maxItems = maxItems; while (initialSize-- > 0) { this.free.Push(allocateDelegate()); } }
private static object AllocateByInternal(Type type) { if (!allocateIsInitialized) { lock (typeof(TypeHelper)) { if (!allocateIsInitialized) { allocateIsInitialized = true; var allocateMethod = typeof(RuntimeTypeHandle).GetMethod(AllocateMethodName, BindingFlags.NonPublic | BindingFlags.Static); if (allocateMethod != null) { allocate = MethodHelper.CreateDelegate <AllocateDelegate>(allocateMethod, SignatureLevels.Cast); } var stubHelpersType = Type.GetType(StubHelpersTypeName); if (stubHelpersType != null) { var allocateInternalMethod = stubHelpersType.GetMethod(AllocateInternalName, BindingFlags.Static | BindingFlags.NonPublic); if (allocateInternalMethod != null) { allocateInternal = MethodHelper.CreateDelegate <AllocateInternalDelegate>(allocateInternalMethod, SignatureLevels.Cast); } } var activationServicesType = Type.GetType(ActivationServicesTypeName); if (activationServicesType != null) { var allocateUninitializedClassInstanceMethod = activationServicesType.GetMethod(AllocateUninitializedClassInstanceName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (allocateUninitializedClassInstanceMethod != null) { allocateUninitializedClassInstance = MethodHelper.CreateDelegate <AllocateUninitializedClassInstanceDelegate>(allocateUninitializedClassInstanceMethod, SignatureLevels.Cast); } } } } } if (allocate != null) { try { return(allocate(type)); } catch (Exception) { } } if (allocateInternal != null) { try { return(allocateInternal(type.TypeHandle.Value)); } catch (Exception) { } } if (allocateUninitializedClassInstance != null) { try { return(allocateUninitializedClassInstance(type)); } catch (Exception) { } } return(null); }
public CustomAllocatedObjectPool(AllocateDelegate allocate, FreeDelegate free, int initialSize) : this(allocate, free, initialSize, 0) { }
public CustomAllocatedObjectPool(AllocateDelegate allocate, FreeDelegate free) : this(allocate, free, 0, 0) { }