/// <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); } }
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(); } }
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]); } }