예제 #1
0
 /// <summary>Returns true when new item was allocated</summary>
 public bool AllocateOrCreate(out Droplet droplet)
 {
     using (_activeLock.Acquire())
     {
         var flag = currentUsed < _baseCapacity;
         droplet = flag ? _unused[currentUsed++] : IncreaseQueueSize();
         _active.Add(droplet);
         return(flag);
     }
 }
예제 #2
0
 public DropletPool(int baseCapacity)
 {
     _baseCapacity = baseCapacity;
     _unused       = new Droplet[baseCapacity];
     _active       = new List <Droplet>();
     for (int i = 0; i < _baseCapacity; i++)
     {
         _unused[i] = new Droplet();
     }
 }
예제 #3
0
        public Droplet IncreaseQueueSize()
        {
            using (_activeLock.Acquire())
            {
                _baseCapacity += 10000;
                Array.Resize(ref _unused, _baseCapacity);
                for (int i = currentUsed++; i < _unused.Length; i++)
                {
                    _unused[i] = new Droplet();
                }

                return(_unused[currentUsed]);
            }
        }