示例#1
0
 internal ByteArray(SegmentSize size)
 {
     this.SegmentSize   = size;
     _segmentSizeValue  = size.Value;
     _segments          = new List <byte[]>();
     _lastSegmentOffset = 0;
     this.Length        = 0;
     this.ReadPosition  = 0;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="segmentSize">每个数组段的大小,当经常接收较大的字节数时,请设置segmentSize为一个较大值,当经常接收较小的字节数时,请设置segmentSize为一个较小值</param>
 /// <param name="idleTime">限制时间,单位 秒,如果数组段等缓存的对象闲置超过闲置时间,那么销毁池对象</param>
 internal ByteArrayPool(SegmentSize size)
 {
     _size      = size;
     _bytesPool = new Pool <ByteArray>(() =>
     {
         return(new ByteArray(_size.Value));
     }, (bytes, phase) =>
     {
         bytes.Clear();
         return(true);
     }, new PoolConfig()
     {
         MaxRemainTime = 600
     });
 }
示例#3
0
 /// <summary>
 /// 从字节缓冲区中借用字节数组
 /// </summary>
 /// <param name="segmentSize"></param>
 /// <returns></returns>
 public static IPoolItem <ByteArray> Borrow(SegmentSize segmentSize)
 {
     return(Global.BorrowBytes(segmentSize));
 }
示例#4
0
 /// <summary>
 /// 根据数据的大小,自动判断段大小
 /// </summary>
 /// <param name="dataLength"></param>
 /// <returns></returns>
 private IPoolItem <ByteArray> BorrowBytes(int dataLength)
 {
     return(BorrowBytes(SegmentSize.GetAdviceSize(dataLength)));
 }
示例#5
0
        /// <summary>
        /// 使用方式:
        /// using(var temp = buffer.GetBytes(ByteSegmentSize.Byte256))
        /// {
        ///     var bytes = temp.Items;
        /// }
        /// </summary>
        /// <param name="segmentSize"></param>
        /// <returns></returns>
        private IPoolItem <ByteArray> BorrowBytes(SegmentSize segmentSize)
        {
            var pool = _pools.Get(segmentSize);

            return(pool.Borrow());
        }
示例#6
0
        public static IPoolItem <SegmentReaderSlim> Borrow(SegmentSize segmentSize)
        {
            var pool = _getPool(segmentSize.Value);

            return(pool.Borrow());
        }
示例#7
0
 internal ByteArray(int dataLength)
     : this(SegmentSize.GetAdviceSize(dataLength))
 {
 }