Reduce garbage generated in StringBuilder marshaling
authorstephentoub <stoub@microsoft.com>
Wed, 7 Oct 2015 16:48:53 +0000 (12:48 -0400)
committerstephentoub <stoub@microsoft.com>
Wed, 7 Oct 2015 17:05:22 +0000 (13:05 -0400)
commitbf7a89cb0545b1c1f8d003770b7e8c71786f1ecb
tree17f83ee00977b3245112047bcc623c2f127eb3be
parent1f21a82ee179d10882c22952c46617b6c9bc88b4
Reduce garbage generated in StringBuilder marshaling

When marshaling a StringBuilder In as Ansi (both done by default on Unix), we currently allocate enough native memory to hold the result.  But then we use AnsiCharMarshaler.DoAnsiConversion to allocate a managed byte array and fill it with the converted results, and then we copy those results into the native memory.  We can instead just call String's ConvertToAnsi directly, avoiding the extra managed array allocation and the extra memory copy.
src/mscorlib/src/System/StubHelpers.cs