public EnumerableOperation(IReplacer replacer, int bufferSize) : base(replacer) { this.bufferSize = bufferSize; this.firstNode = new BufferNode(); this.lastNode = firstNode; }
public BufferNode SetNextNode(int bufferSize) { return this.next = new BufferNode(bufferSize, this.totalCapacity, this); }
private BufferNode(int bufferSize, int currentCapacity, BufferNode previous) { this.buffer = new string[bufferSize]; this.totalCapacity = currentCapacity + bufferSize; this.previous = previous; }
private BufferNode IncreaseBuffer(bool shallWait, long i) { var lockTaken = false; var node = default(BufferNode); if (shallWait) { this.spinLock.Enter(ref lockTaken); if (!lockTaken) throw new Exception("An unknown exception has occurred."); } else { this.spinLock.TryEnter(ref lockTaken); if (!lockTaken) return node; } if (i >= this.lastNode.TotalCapacity) { do { // TODO: obtain string array from array pool instead of initializing new instance everytime. this.lastNode = this.lastNode.SetNextNode(this.bufferSize); } while (i >= this.lastNode.TotalCapacity); node = this.lastNode; #if DEBUG if (shallWait) Debug.WriteLine("Buffer increased after composing string. (index = {0})", i); else Debug.WriteLine("Buffer increased before composing string. (index = {0})", i); #endif } this.spinLock.Exit(); return node; }