Esempio n. 1
0
        public ObjectPool(ObjectPoolAllocator <T> objectAllocator, Action <T> objectDeallocator, int initialSize)
        {
            this.objectAllocator   = objectAllocator;
            this.objectDeallocator = objectDeallocator;
            this.initialSize       = initialSize;
            autoReleaseMemory      = true;
            objectIndex            = 0;

            objects = new List <T>(initialSize);
            for (int i = 0; i < initialSize; i++)
            {
                objects.Add(this.objectAllocator.action(this.objectAllocator.arg));
            }
        }
Esempio n. 2
0
        public ObjectPool(Func <T, T> allocator, int initialSize, bool autoReleaseMememory)
        {
            objectAllocator   = new ObjectPoolAllocator <T>(allocator);
            objectDeallocator = null;
            this.initialSize  = initialSize;
            autoReleaseMemory = autoReleaseMememory;
            objectIndex       = 0;

            objects = new List <T>(initialSize);
            for (int i = 0; i < initialSize; i++)
            {
                objects.Add(objectAllocator.action(objectAllocator.arg));
            }
        }