Memory growth algorithm improvement in coreconsole (dotnet/coreclr#7870)
authorRoman Shchekin <mrqtros@gmail.com>
Thu, 10 Nov 2016 00:06:40 +0000 (03:06 +0300)
committerDan Moseley <danmose@microsoft.com>
Thu, 10 Nov 2016 00:06:40 +0000 (16:06 -0800)
* Now Append will work properly if strLen is big (for example 3xm_capacity). And value 1.5 is better for memory growth.

* Correct way of calculating 1.5 (without floating point calculation, thanks mikedn)

* After long discussion we decided that simple and aggressive allocation is better for this case

Commit migrated from https://github.com/dotnet/coreclr/commit/c637c919adcd0c0d7fcd8818810bcb727408fa51

src/coreclr/src/coreclr/hosts/coreconsole/coreconsole.cpp

index 7abc02a..ea4e2e7 100644 (file)
@@ -44,7 +44,7 @@ public:
             m_capacity = m_defaultSize;
         }
         if (m_length + strLen + 1 > m_capacity) {
-            size_t newCapacity = m_capacity * 2;
+            size_t newCapacity = (m_length + strLen + 1) * 2;
             wchar_t* newBuffer = new wchar_t[newCapacity];
             wcsncpy_s(newBuffer, newCapacity, m_buffer, m_length);
             delete[] m_buffer;