public static byte[] GetBuffer(int expectedSize) { if (expectedSize <= 0) { throw new Exception("expectedSize must > 0!"); } Queue <byte[]> bufferCache = null; byte[] buffer = null; lock (bufferPool) { #if UNITY_EDITOR bufferDetecter.IncreseInstance(); #endif if (!bufferPool.TryGetValue(expectedSize, out bufferCache)) { bufferCache = new Queue <byte[]>(); bufferPool.Add(expectedSize, bufferCache); } if (bufferCache.Count > 0) { bufferCount--; buffer = bufferCache.Dequeue(); } } if (buffer == null) { buffer = new byte[expectedSize]; } return(buffer); }
public static StreamBuffer GetStream(int expectedSize, bool canWrite, bool canRead) { if (expectedSize <= 0) { throw new Exception("expectedSize must > 0!"); } Queue <StreamBuffer> streamCache = null; StreamBuffer streamBuffer = null; lock (streamPool) { #if UNITY_EDITOR streamDetecter.IncreseInstance(); #endif if (!streamPool.TryGetValue(expectedSize, out streamCache)) { streamCache = new Queue <StreamBuffer>(); streamPool.Add(expectedSize, streamCache); } if (streamCache.Count > 0) { streamCount--; streamBuffer = streamCache.Dequeue(); streamBuffer.SetOperate(canWrite, canRead); } } if (streamBuffer == null) { streamBuffer = new StreamBuffer(expectedSize, canWrite, canRead); } return(streamBuffer); }
public static DelegateAction Get() { lock (pool) { #if UNITY_EDITOR detecter.IncreseInstance(); #endif if (pool.Count > 0) { return(pool.Dequeue()); } } DelegateAction instance = new DelegateAction(); BetterDelegate.Add(instance); return(instance); }