public AstNodePool() { // Filling 21st container would mean having tokens occupy 4 GB RAM m_AstNodeContainers = new AstNodeContainer[15]; m_AstNodeContainers[0] = m_CurrentContainer = new AstNodeContainer(m_AllocationCapacity); m_CurrentContainerIndex = 0; m_ContainerCount = 1; }
private void AddContainer() { m_CurrentContainerIndex++; if (m_ContainerCount == m_CurrentContainerIndex) { m_AllocationCapacity *= 2; m_AstNodeContainers[m_ContainerCount++] = m_CurrentContainer = new AstNodeContainer(m_AllocationCapacity); } else { m_CurrentContainer = m_AstNodeContainers[m_CurrentContainerIndex]; } }
public unsafe void FreeMemory(AstNode.InternalNode *ptr) { for (; ;) { if (m_CurrentContainer.IsMyPtr((byte *)ptr)) { m_CurrentContainer.ResetTo((byte *)ptr); return; } else { m_CurrentContainer.ResetToZero(); m_CurrentContainerIndex--; m_CurrentContainer = m_AstNodeContainers[m_CurrentContainerIndex]; } } }