public ByteBuf Allocate() { ByteBuf byteBuf; if (q050.Allocate(out byteBuf) || q025.Allocate(out byteBuf) || q000.Allocate(out byteBuf) || qInit.Allocate(out byteBuf) || q075.Allocate(out byteBuf)) { return(byteBuf); } // Add a new chunk and allocate a segment from it. try { var chunk = ByteBufChunk.NewChunk(this, SegmentSize, ChunkSize, isUnsafe); if (!chunk.Allocate(out byteBuf)) { logger.LogError("Failed to allocate a ByteBuf from a new ByteBufChunk - isUnsafe [{0}].", isUnsafe); return(null); } qInit.Add(chunk); return(byteBuf); } catch (Exception e) { logger.LogException(e); return(null); } }
public ByteBuf Allocate() { var trial = 0; ByteBuf byteBuf; do { if (q050.Allocate(out byteBuf) || q025.Allocate(out byteBuf) || q000.Allocate(out byteBuf) || qInit.Allocate(out byteBuf) || q075.Allocate(out byteBuf)) { return(byteBuf); } // Issues a pause instruction on each loop iteration, // and not fall back to a more expensive wait on. Thread.Sleep(0); trial++; } while (trial < TrialsCount); // Add a new chunk and allocate a segment from it. try { var chunk = ByteBufChunk.NewChunk(this, SegmentSize, ChunkSize, isUnsafe); if (!chunk.Allocate(out byteBuf)) { logger.LogError("Failed to allocate a ByteBuf from a new ByteBufChunk - isUnsafe [{0}].", isUnsafe); return(null); } qInit.Add(chunk); return(byteBuf); } catch (Exception e) { logger.LogException(e); return(null); } }