Exemple #1
0
        public ObjectPool(ObjectPoolAllocator <T> objectAllocator, Action <T> objectDeallocator, int initialSize)
        {
            m_objectAllocator   = objectAllocator;
            m_objectDeallocator = objectDeallocator;
            m_initialSize       = initialSize;
            m_autoReleaseMemory = true;
            m_objectIndex       = 0;

            m_objects = new List <T>(initialSize);
            for (int i = 0; i < initialSize; i++)
            {
                m_objects.Add(m_objectAllocator.Action(m_objectAllocator.Arg));
            }
        }
Exemple #2
0
        public ObjectPool(Func <T, T> objectAllocator, int initialSize, bool autoReleaseMememory)
        {
            m_objectAllocator   = new ObjectPoolAllocator <T>(objectAllocator);
            m_objectDeallocator = null;
            m_initialSize       = initialSize;
            m_autoReleaseMemory = autoReleaseMememory;
            m_objectIndex       = 0;

            m_objects = new List <T>(initialSize);
            for (int i = 0; i < initialSize; i++)
            {
                m_objects.Add(m_objectAllocator.Action(m_objectAllocator.Arg));
            }
        }