/// <summary>
 /// 释放数据容器
 /// </summary>
 public virtual void Close()
 {
     if (IsUnmanaged)
     {
         Unmanaged.Free(ref Data);
         IsUnmanaged       = false;
         Data.CurrentIndex = 0;
     }
     else
     {
         Data.SetNull();
     }
     LastPrepSize = 0;
 }
Beispiel #2
0
 /// <summary>
 /// 释放缓冲区
 /// </summary>
 /// <param name="head"></param>
 private void clear(byte *head)
 {
     while (*(byte **)head != null)
     {
         byte *next = *(byte **)head;
         Unmanaged.FreePool(head, Size);
         if (*(byte **)next == null)
         {
             head = next;
             break;
         }
         head = *(byte **)next;
         Unmanaged.FreePool(next, Size);
     }
     Unmanaged.FreePool(head, Size);
 }
Beispiel #3
0
        /// <summary>
        /// 保存缓冲区
        /// </summary>
        /// <param name="buffer">缓冲区</param>
        public void Push(ref Pointer buffer)
        {
            int size = System.Threading.Interlocked.Exchange(ref buffer.ByteSize, 0);

            if (size != 0)
            {
                if (size == Size)
                {
                    Push((byte *)buffer.GetDataClearOnly());
                }
                else
                {
                    Unmanaged.Free(ref buffer, size);
                }
            }
        }
 /// <summary>
 /// 重置数据
 /// </summary>
 /// <param name="size">数据字节长度</param>
 internal virtual void Reset(int size = UnmanagedPool.TinySize)
 {
     if (size <= 0)
     {
         size = UnmanagedPool.TinySize;
     }
     if (size != Data.ByteSize)
     {
         if (IsUnmanaged)
         {
             Unmanaged.Free(ref this.Data);
             IsUnmanaged = false;
         }
         Data        = Unmanaged.GetPointer(size, false);
         IsUnmanaged = true;
     }
     Data.CurrentIndex = LastPrepSize = 0;
 }
        /// <summary>
        /// 设置容器字节尺寸
        /// </summary>
        /// <param name="size">容器字节尺寸</param>
        protected void setStreamSize(int size)
        {
#if DEBUG
            if (size <= 0)
            {
                throw new Exception(size.toString() + " <= 0");
            }
#endif
            if (size < UnmanagedPool.TinySize)
            {
                size = UnmanagedPool.TinySize;
            }
            Pointer newData = Unmanaged.GetPointer(size, false);
            Data.CopyTo(ref newData);
            if (IsUnmanaged)
            {
                Unmanaged.Free(ref Data);
            }
            Data        = newData;
            IsUnmanaged = true;
        }
Beispiel #6
0
 internal Pointer GetMinSize(int minSize)
 {
     return(minSize <= Size?GetPointer() : Unmanaged.GetPointer(minSize, false));
 }
Beispiel #7
0
        public Pointer GetPointer()
        {
            byte *data = tryGet();

            return(data != null ? new Pointer(data, Size) : Unmanaged.GetPointer(Size, false));
        }