Exemplo n.º 1
0
 internal void PushOnly(ref Pointer.Size buffer)
 {
     if (buffer.ByteSize == Size)
     {
         Push(buffer.Byte);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 内存数据流转换
 /// </summary>
 /// <param name="stream">内存数据流</param>
 internal virtual void From(UnmanagedStreamBase stream)
 {
     IsUnmanaged        = stream.IsUnmanaged;
     Data               = stream.Data;
     ByteSize           = stream.ByteSize;
     LastPrepSize       = stream.LastPrepSize;
     stream.IsUnmanaged = false;
 }
Exemplo n.º 3
0
 internal static void FreeStatic(ref Pointer.Size data)
 {
     if (data.Data != null)
     {
         Marshal.FreeHGlobal((IntPtr)data.Data);
         Interlocked.Add(ref staticSize, -data.ByteSize);
         data.SetNull();
     }
 }
        public void Push(ref Pointer.Size buffer)
        {
            byte *data = buffer.Byte;

            buffer.Data = null;
            if (data != null && buffer.ByteSize == Size)
            {
                Push(data);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// 超时计数
 /// </summary>
 /// <param name="maxSeconds">最大超时秒数,必须大于 0</param>
 internal TimeoutCount(int maxSeconds)
 {
     if (maxSeconds > 0)
     {
         Counts            = Unmanaged.GetSize64((maxSeconds + 2) << 2, true);
         Counts.CustomSize = Counts.ByteSize >> 2;
         OnTimerLink.PushNotNull(this);
         isPushEvents = 1;
     }
 }
Exemplo n.º 6
0
 internal static void Free(ref Pointer.Size data, bool isStaticUnmanaged)
 {
     if (isStaticUnmanaged)
     {
         FreeStatic(ref data);
     }
     else
     {
         Free(ref data);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 获取匹配值集合
        /// </summary>
        /// <param name="isValue">数据匹配器</param>
        /// <returns>匹配值集合</returns>
        public unsafe valueType[] GetFindArray(Func <valueType, bool> isValue)
        {
            if (Length == 0)
            {
                return(NullValue <valueType> .Array);
            }
            int           length = ((Length + 63) >> 6) << 3;
            UnmanagedPool pool   = AutoCSer.UnmanagedPool.GetDefaultPool(length);

            Pointer.Size buffer = pool.GetSize64(length);
            try
            {
                Memory.ClearUnsafe(buffer.ULong, length >> 3);
                return(getFindArray(isValue, new MemoryMap(buffer.Data)));
            }
            finally { pool.PushOnly(ref buffer); }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 重建数据
        /// </summary>
        protected void create()
        {
            int heapIndex = Array.Length, newCount = heapIndex << 1, newHeapSize = newCount * sizeof(int);

            KeyValue <keyType, valueType>[] newArray = new KeyValue <keyType, valueType> [newCount];
            Pointer.Size newHeap = Unmanaged.Get(newHeapSize, false, isStaticUnmanaged), oldHeap = Heap;
            int *        newHeapFixed = newHeap.Int;

            Array.CopyTo(newArray, 0);
            AutoCSer.Memory.CopyNotNull(Heap.Byte, newHeapFixed, newHeapSize >> 1);
            do
            {
                --newCount;
                newHeapFixed[newCount] = newCount;
            }while (newCount != heapIndex);
            Array = newArray;
            Heap  = newHeap;
            Unmanaged.Free(ref oldHeap, isStaticUnmanaged);
        }
Exemplo n.º 9
0
 /// <summary>
 /// 清除数据
 /// </summary>
 internal void Clear()
 {
     if (Array.Length == defaultArrayLength)
     {
         int *heapFixed = Heap.Int;
         if (*heapFixed != 0)
         {
             reset(heapFixed);
             System.Array.Clear(Array, 0, Array.Length);
         }
     }
     else
     {
         KeyValue <keyType, valueType>[] newArray = new KeyValue <keyType, valueType> [defaultArrayLength];
         Pointer.Size newHeap = Unmanaged.Get(defaultArrayLength * sizeof(int), false, isStaticUnmanaged), oldHeap = Heap;
         reset(newHeap.Int);
         Array = newArray;
         Heap  = newHeap;
         Unmanaged.Free(ref oldHeap, isStaticUnmanaged);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// 数组模拟最小堆
 /// </summary>
 /// <param name="isStaticUnmanaged">是否固定内存申请</param>
 internal ArrayHeap(bool isStaticUnmanaged = false)
 {
     Array = new KeyValue <keyType, valueType> [defaultArrayLength];
     Heap  = Unmanaged.Get(defaultArrayLength * sizeof(int), false, this.isStaticUnmanaged = isStaticUnmanaged);
     reset(Heap.Int);
 }