Exemplo n.º 1
0
        /// <summary>
        /// 索引池
        /// </summary>
        public indexPool()
        {
            int size = fastCSharp.config.appSetting.PoolSize * sizeof(int);

            currentFreeIndex = (freeIndexs = unmanaged.Get(size, false)).Int;
            endFreeIndex     = freeIndexs.Byte + size;
        }
Exemplo n.º 2
0
 /// <summary>
 /// 内存数据流转换
 /// </summary>
 /// <param name="stream">内存数据流</param>
 protected internal unmanagedStreamBase(unmanagedStreamBase stream)
 {
     data               = stream.data;
     length             = stream.length;
     IsUnmanaged        = stream.IsUnmanaged;
     stream.IsUnmanaged = false;
 }
Exemplo n.º 3
0
 /// <summary>
 /// 释放对象
 /// </summary>
 /// <param name="index"></param>
 public void UnsafeFree(int index)
 {
     Monitor.Enter(poolLock);
     if (currentFreeIndex != null)
     {
         if (currentFreeIndex == endFreeIndex)
         {
             pointer.size oldIndex = new pointer.size();
             int          size     = (int)(endFreeIndex - freeIndexs.Byte);
             try
             {
                 pointer.size newIndex = unmanaged.Get(size <<= 1, false);
                 byte *       newEnd   = newIndex.Byte + size;
                 oldIndex = freeIndexs;
                 fastCSharp.unsafer.memory.Copy(oldIndex.data, newIndex.data, size = (int)((byte *)currentFreeIndex - oldIndex.Byte));
                 endFreeIndex     = newEnd;
                 freeIndexs       = newIndex;
                 currentFreeIndex = (int *)(newIndex.Byte + size);
             }
             finally
             {
                 if (oldIndex.data == null)
                 {
                     Monitor.Exit(poolLock);
                 }
             }
             unmanaged.Free(ref oldIndex);
         }
         pool[index]         = null;
         *currentFreeIndex++ = index;
     }
     Monitor.Exit(poolLock);
 }
Exemplo n.º 4
0
 /// <summary>
 /// 内存数据流转换
 /// </summary>
 /// <param name="stream">内存数据流</param>
 internal virtual void From(unmanagedStreamBase stream)
 {
     IsUnmanaged        = stream.IsUnmanaged;
     data               = stream.data;
     length             = stream.length;
     stream.IsUnmanaged = false;
 }
Exemplo n.º 5
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 = isStaticUnmanaged ? unmanaged.GetStaticSize(newHeapSize, false) : unmanaged.Get(newHeapSize, false), oldHeap = heap;
            int *        newHeapFixed = newHeap.Int;

            array.CopyTo(newArray, 0);
            fastCSharp.unsafer.memory.Copy(heap.Byte, newHeapFixed, newHeapSize >> 1);
            do
            {
                --newCount;
                newHeapFixed[newCount] = newCount;
            }while (newCount != heapIndex);
            array = newArray;
            heap  = newHeap;
            if (isStaticUnmanaged)
            {
                unmanaged.FreeStatic(ref oldHeap);
            }
            else
            {
                unmanaged.Free(ref oldHeap);
            }
        }
Exemplo n.º 6
0
 public static void FreeStatic(ref pointer.size data)
 {
     if (data.data != null)
     {
         Interlocked.Add(ref staticSize, -data.sizeValue);
         Marshal.FreeHGlobal((IntPtr)data.data);
         data.Null();
     }
 }
Exemplo n.º 7
0
 public void Push(ref pointer.size buffer)
 {
     if (buffer.sizeValue == Size)
     {
         push(ref buffer.data);
     }
     else
     {
         unmanaged.Free(ref buffer);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// 数组模拟最小堆
        /// </summary>
        /// <param name="isStaticUnmanaged">是否固定内存申请</param>
        internal arrayHeap(bool isStaticUnmanaged)
        {
            this.isStaticUnmanaged = isStaticUnmanaged;
            array = new keyValue <keyType, valueType> [defaultArrayLength];
            heap  = isStaticUnmanaged ? unmanaged.GetStaticSize(defaultArrayLength * sizeof(int), false) : unmanaged.Get(defaultArrayLength * sizeof(int), false);
            int *heapFixed = heap.Int;

            for (int index = defaultArrayLength; index != 0; heapFixed[index] = index)
            {
                --index;
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Dispose()
 {
     if (currentFreeIndex != null)
     {
         Monitor.Enter(poolLock);
         pointer.size indexs = freeIndexs;
         pool             = nullValue <valueType> .Array;
         poolIndex        = 0;
         currentFreeIndex = null;
         endFreeIndex     = null;
         freeIndexs.Null();
         Monitor.Exit(poolLock);
         unmanaged.Free(ref indexs);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// 设置容器尺寸
 /// </summary>
 /// <param name="length">容器尺寸</param>
 protected void setStreamLength(int length)
 {
     if (length < DefaultLength)
     {
         length = DefaultLength;
     }
     pointer.size newData = unmanaged.Get(length, false);
     fastCSharp.unsafer.memory.Copy(data.data, newData.data, this.length);
     if (IsUnmanaged)
     {
         unmanaged.Free(ref data);
     }
     data        = newData;
     IsUnmanaged = true;
 }
Exemplo n.º 11
0
 /// <summary>
 /// 清除缓冲区集合
 /// </summary>
 /// <param name="count">保留清除缓冲区数量</param>
 private void clear(int count)
 {
     pointer.size pointerSize = new pointer.size();
     foreach (pointer pointer in pool.GetClear(count, false))
     {
         try
         {
             pointerSize.Set(pointer.Data, Size);
             unmanaged.Free(ref pointerSize);
         }
         catch (Exception error)
         {
             log.Error.Add(error, null, false);
         }
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// 静态哈希集合
 /// </summary>
 /// <param name="values">哈希数据集合</param>
 public unsafe staticHashSet(valueType[] values)
 {
     if (values.length() != 0)
     {
         unmanagedPool pool = fastCSharp.unmanagedPool.GetDefaultPool(values.Length * sizeof(int));
         pointer.size  data = pool.Get(values.Length * sizeof(int));
         try
         {
             getValues(values, data.Int);
         }
         finally { pool.Push(ref data); }
     }
     else
     {
         indexs = defaultIndexs;
         array  = nullValue <valueType> .Array;
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// 非托管内存数据流
 /// </summary>
 /// <param name="length">容器初始尺寸</param>
 protected unmanagedStreamBase(int length)
 {
     data        = unmanaged.Get(length > 0 ? length : DefaultLength, false);
     IsUnmanaged = true;
 }