public MemoryContainer(int capacity) { do { m_Current = m_Memory = (byte *)NativeFunctions.AllocateProcessMemory(capacity).ToPointer(); m_End = m_Current + capacity; }while (m_Memory == null && (capacity /= 2) > 64); if (m_Memory == null) { throw new OutOfMemoryException(); } }
private void Reallocate() { var oldPtr = m_Ptr; m_Ptr = (char *)NativeFunctions.AllocateProcessMemory(kSizeOfChar * (m_Capacity + 1)); // +2 part comes so FastString could copy 4 bytes at a time for (int i = 0; i < m_Length; i++) { m_Ptr[i] = oldPtr[i]; } NativeFunctions.FreeProcessMemory((IntPtr)oldPtr); }
public AstNodeContainer(int capacity) { do { var byteCount = capacity * kNodeSize; m_NextNode = m_Nodes = (byte *)NativeFunctions.AllocateProcessMemory(byteCount); m_End = m_Nodes + byteCount; }while (m_Nodes == null && (capacity /= 2) > 64); if (m_Nodes == null) { throw new OutOfMemoryException(); } }
public FastStringBuilder(string str) { var strLength = str.Length; m_Capacity = m_Length = strLength; m_Ptr = (char *)NativeFunctions.AllocateProcessMemory(kSizeOfChar * (m_Capacity + 1)); fixed(char *src = str) { for (int i = 0; i < strLength; i++) { m_Ptr[i] = src[i]; } } }
static FastString() { kPointerToNullChar = (char *)NativeFunctions.AllocateProcessMemory(1); *kPointerToNullChar = '\0'; kEmpty.m_Buffer = kPointerToNullChar; }
public FastStringBuilder() { m_Capacity = kInitialCapacity; m_Ptr = (char *)NativeFunctions.AllocateProcessMemory(kSizeOfChar * (m_Capacity + 1)); }