public IChunk Alloc(int allocsize, out int offset) { lock (this) { offset = -1; int maxbuffsize = _buffsize * MAX_BEI; if (allocsize > maxbuffsize) { IChunk bc = new BigChunk(allocsize); offset = 0; AddChunk(bc); return(bc); } else { int needsize = allocsize; if (allocsize % _buffsize != 0) { needsize = (allocsize / _buffsize + 1) * _buffsize; } IChunk p = _headChunk; while (p != null) { if (p.BufferSize == needsize) { offset = p.AllocBuffer(); if (offset >= 0) { return(p); } } p = p.Next; } IChunk bc = new MinChunk(COUNT_PERCHUNK, needsize); offset = bc.AllocBuffer(); AddChunk(bc); return(bc); } } }