示例#1
0
        /// <summary>
        /// Retrieves a PooledBitWriter
        /// </summary>
        /// <param name="stream">The stream the writer should write to</param>
        /// <returns>A PooledBitWriter</returns>
        public static PooledBitWriter GetWriter(Stream stream)
        {
            if (writers.Count == 0)
            {
                if (createdWriters == 254)
                {
                    if (LogHelper.CurrentLogLevel <= LogLevel.Normal)
                    {
                        LogHelper.LogWarning("255 writers have been created. Did you forget to dispose?");
                    }
                    else if (createdWriters < 255)
                    {
                        createdWriters++;
                    }
                }

                return(new PooledBitWriter(stream));
            }

            PooledBitWriter writer = writers.Dequeue();

            writer.SetStream(stream);

            return(writer);
        }
示例#2
0
        /// <summary>
        /// Gets a PooledBitWriter from the static BitWriterPool
        /// </summary>
        /// <returns>PooledBitWriter</returns>
        public static PooledBitWriter Get(Stream stream)
        {
            PooledBitWriter writer = BitWriterPool.GetWriter(stream);

            writer.isDisposed = false;
            return(writer);
        }
 /// <summary>
 /// Puts a PooledBitWriter back into the pool
 /// </summary>
 /// <param name="writer">The writer to put in the pool</param>
 public static void PutBackInPool(PooledBitWriter writer)
 {
     if (writers.Count < 64)
     {
         writers.Enqueue(writer);
     }
     else
     {
         Debug.Log("BitWriterPool already has 64 queued. Throwing to GC. Did you forget to dispose?");
     }
 }
示例#4
0
 /// <summary>
 /// Puts a PooledBitWriter back into the pool
 /// </summary>
 /// <param name="writer">The writer to put in the pool</param>
 public static void PutBackInPool(PooledBitWriter writer)
 {
     if (writers.Count < 64)
     {
         writers.Enqueue(writer);
     }
     else if (LogHelper.CurrentLogLevel <= LogLevel.Developer)
     {
         LogHelper.LogInfo("BitWriterPool already has 64 queued. Throwing to GC. Did you forget to dispose?");
     }
 }