public MemoryBlock PopMemoryBlock(int needSize) { try { int index = TMSKThreadStaticClass.Log2(needSize); int blockSize = this.MemoryBlockSizeArray[index]; if (blockSize > 0) { if (blockSize < needSize) { index++; } if (this.MemoryBlockStackArray[index].Count > 0) { return(this.MemoryBlockStackArray[index].Pop()); } return(Global._MemoryManager.Pop(needSize)); } else { if (this.MemoryBlockStackArray[index].Count > 0) { return(this.MemoryBlockStackArray[index].Pop()); } return(Global._MemoryManager.Pop((int)Math.Pow(2.0, (double)index))); } } catch (Exception ex) { DataHelper.WriteExceptionLogEx(ex, ""); } return(null); }
public void PushMemoryBlock(MemoryBlock item) { try { int index = TMSKThreadStaticClass.Log2(item.BlockSize); int blockSize = this.MemoryBlockSizeArray[index]; if (blockSize > 0) { if (blockSize < item.BlockSize) { index++; } if (this.MemoryBlockStackArray[index].Count <= this.MemoryBlockNumArray[index]) { this.MemoryBlockStackArray[index].Push(item); } else { Global._MemoryManager.Push(item); } } else if (this.MemoryBlockStackArray[index].Count <= this.MemoryBlockNumArray[index]) { this.MemoryBlockStackArray[index].Push(item); } else { Global._MemoryManager.Push(item); } } catch (Exception ex) { DataHelper.WriteExceptionLogEx(ex, ""); } }
public static TMSKThreadStaticClass GetInstance() { if (null == ThreadStaticClass) { ThreadStaticClass = new TMSKThreadStaticClass(); } return(ThreadStaticClass); }
public TMSKThreadStaticClass() { foreach (KeyValuePair <int, int> kv in GameManager.MemoryPoolConfigDict) { int index = TMSKThreadStaticClass.Log2(kv.Key); if (index < this.MemoryBlockNumArray.Length) { this.MemoryBlockStackArray[index] = new Stack <MemoryBlock>(); this.MemoryBlockNumArray[index] = Math.Max(10, kv.Value / 100); this.MemoryBlockSizeArray[index] = kv.Key; } } Stack <MemoryBlock> lastStackMemoryBlock = null; int lastMemoryBlockNum = 10; int lastMemoryBlockSize = 0; for (int i = this.MemoryBlockStackArray.Length - 1; i >= 0; i--) { if (null == this.MemoryBlockStackArray[i]) { if (null == lastStackMemoryBlock) { this.MemoryBlockStackArray[i] = new Stack <MemoryBlock>(); this.MemoryBlockNumArray[i] = 10; this.MemoryBlockSizeArray[i] = 0; } else { this.MemoryBlockStackArray[i] = lastStackMemoryBlock; this.MemoryBlockNumArray[i] = lastMemoryBlockNum; this.MemoryBlockSizeArray[i] = lastMemoryBlockSize; } } else { lastStackMemoryBlock = this.MemoryBlockStackArray[i]; lastMemoryBlockNum = this.MemoryBlockNumArray[i]; lastMemoryBlockSize = this.MemoryBlockSizeArray[i]; } } }