コード例 #1
0
ファイル: ResourcePool.cs プロジェクト: bejita968/MLAPI
 /// <summary>
 /// Puts a PooledBitReader back into the pool
 /// </summary>
 /// <param name="reader">The reader to put in the pool</param>
 public static void PutBackInPool(PooledBitReader reader)
 {
     if (readers.Count < 64)
     {
         readers.Enqueue(reader);
     }
     else if (LogHelper.CurrentLogLevel <= LogLevel.Developer)
     {
         LogHelper.LogInfo("BitReaderPool already has 64 queued. Throwing to GC. Did you forget to dispose?");
     }
 }
コード例 #2
0
        /// <summary>
        /// Reads the contents from the stream and applies it to the type instance
        /// </summary>
        /// <param name="stream">The stream to read from</param>
        public virtual void Read(Stream stream)
        {
            FieldInfo[] fields = SerializationManager.GetFieldsForType(GetType());

            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                for (int i = 0; i < fields.Length; i++)
                {
                    fields[i].SetValue(this, reader.ReadObjectPacked(fields[i].FieldType));
                }
            }
        }