Example #1
0
        /// <summary>
        /// 添加内存缓冲块,2.5倍于配置的个数,分成10份,以此减少存取时的锁定时间
        /// </summary>
        /// <param name="blockNum"></param>
        /// <param name="blockSize"></param>
        public void AddBatchBlock2(int blockNum, int blockSize)
        {
            blockNum /= ConstSplitePoolNum / 2;

            lock (MemoryDict)
            {
                //加入索引词典
                if (MemoryDict.ContainsKey(blockSize))
                {
                    MemoryDict.Remove(blockSize);
                }

                MemoryStackArray stackArray = new MemoryStackArray();
                for (int idx = 0; idx < ConstSplitePoolNum; idx++)
                {
                    Stack <MemoryBlock> blockList = new Stack <MemoryBlock>();
                    for (int i = 0; i < blockNum; i++)
                    {
                        MemoryBlock mb = new MemoryBlock(blockSize, true);
                        blockList.Push(mb);
                        BlockDict[mb] = 1;
                    }
                    stackArray.StackList[idx] = blockList;
                }
                MemoryDict.Add(blockSize, stackArray);
            }

            lock (BlockSizeList)
            {
                BlockSizeList.Add(blockSize);

                //从小到大排序
                BlockSizeList.Sort();
            }
        }
Example #2
0
 public void AddBatchBlock2(int blockNum, int blockSize)
 {
     blockNum /= 8;
     lock (this.MemoryDict)
     {
         if (this.MemoryDict.ContainsKey(blockSize))
         {
             this.MemoryDict.Remove(blockSize);
         }
         MemoryStackArray stackArray = new MemoryStackArray();
         for (int idx = 0; idx < 16; idx++)
         {
             Stack <MemoryBlock> blockList = new Stack <MemoryBlock>();
             for (int i = 0; i < blockNum; i++)
             {
                 MemoryBlock mb = new MemoryBlock(blockSize, true);
                 blockList.Push(mb);
                 this.BlockDict[mb] = 1;
             }
             stackArray.StackList[idx] = blockList;
         }
         this.MemoryDict.Add(blockSize, stackArray);
     }
     lock (this.BlockSizeList)
     {
         this.BlockSizeList.Add(blockSize);
         this.BlockSizeList.Sort();
     }
 }