-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop mutating strings in StringBuffer
.
#93
Comments
The strings that get mutated in the non-LowTrust version of FParsec are newly allocated and either not externally shared or not mutated afterwards. While this isn't officially supported, this doesn't cause undefined behaviour, data corruption or crashes. If you look at the implementation of the dotnet The only reason that I've been using strings for Your suggestion to use |
Not yet implemented but once https://github.com/dotnet/runtime/blob/main/docs/design/features/StringDeduplication.md lands we will be in trouble. See also dotnet/runtime#27515 and dotnet/runtime#36989 (comment)
Because of its tight coupling with the runtime, |
Thanks for the pointers! I'm curious whether the deduplication will ever land in this form. But you're right, we should get rid of the string mutation in FParsec. |
The
StringBuffer
class is built around allocating big strings, pinning them and mutating them. Mutating strings is undefined behavior and prone to cause crashes or data corruption now or in the future.What I recommend instead is to use
GC.AllocateUninitializedArray
to allocate character arrays in the Pinned Object Heap. With that, the chunking logic will go away (you don't have to allocate a big array and slice it, one allocation per slice is OK, and you don't have to bother with GC handles.I did not include it with #92; this will need to touch code in
CharStream
, something I am not comfortable with. But you can ping me once you have a PR and I can review it.The text was updated successfully, but these errors were encountered: