internal void SplitByteArray(int size) { var splitNode = new BufSlice(this.block, this.Offset + size, this.Total - size); this.Total = size; if (null != this.Next) { this.Next.prev = splitNode; splitNode.Next = this.Next; } this.Next = splitNode; splitNode.prev = this; }
public IBufSlice Alloc(int size) { for (int i = 0; i < this.blocks.Count; ++i) { BufSlice bytes = this.blocks[i].Capture(size); if (bytes != null) { return(bytes); } } var block = new BufBlock(this, Math.Max(GetProperSize(size), MIN_BUFFER_SIZE)); this.blocks.Add(block); return(block.Capture(size)); }
public void Dispose() { Reset(); if (null != this.Next && 0 == this.Next.RefCount) { this.Total += this.Next.Total; this.Next = this.Next.Next; if (null != this.Next) { this.Next.prev = this; } } if (null != this.prev && 0 == this.prev.RefCount) { this.prev.Total += this.Total; this.prev.Next = this.Next; if (null != this.Next) { this.Next.prev = this.prev; } } }
public BufBlock(BufStorage storage, int size) { this.Storage = storage; this.Buffer = new byte[size]; this.header = new BufSlice(this, 0, size); }