public void Add(Int32 amount) { if (!TryAdd(amount)) { throw new InvalidOperationException(ExpressionResources.ExceededAllowedMemory(m_node?.ConvertToExpression())); } }
internal void AddAmount( Int32 depth, Int32 bytes, Boolean trimDepth = false) { // Trim deeper depths if (trimDepth) { while (m_maxActiveDepth > depth) { var amount = m_depths[m_maxActiveDepth]; if (amount > 0) { // Sanity check if (amount > m_totalAmount) { throw new InvalidOperationException("Bytes to subtract exceeds total bytes"); } // Subtract from the total checked { m_totalAmount -= amount; } // Reset the amount m_depths[m_maxActiveDepth] = 0; } m_maxActiveDepth--; } } // Grow the depths if (depth > m_maxActiveDepth) { // Grow the list while (m_depths.Count <= depth) { m_depths.Add(0); } // Adjust the max active depth m_maxActiveDepth = depth; } checked { // Add to the depth m_depths[depth] += bytes; // Add to the total m_totalAmount += bytes; } // Check max if (m_totalAmount > m_maxAmount) { throw new InvalidOperationException(ExpressionResources.ExceededAllowedMemory(m_node?.ConvertToExpression())); } }