stackalloc for UTF8_ToManaged

This commit is contained in:
Ethan Lee 2018-06-27 14:45:19 -04:00
parent a16e9951f7
commit f26b55e8be

View file

@ -89,9 +89,10 @@ namespace SDL2
); );
#else #else
/* Old C# requires an extra memcpy, bleh! */ /* Old C# requires an extra memcpy, bleh! */
byte[] bytes = new byte[ptr - (byte*) s]; int len = (int) (ptr - (byte*) s);
Marshal.Copy(s, bytes, 0, bytes.Length); char* chars = stackalloc char[len];
string result = System.Text.Encoding.UTF8.GetString(bytes); System.Text.Encoding.UTF8.GetChars((byte*) s, len, chars, len);
string result = new string(chars);
#endif #endif
/* Some SDL functions will malloc, we have to free! */ /* Some SDL functions will malloc, we have to free! */