Skip to content

State machines to stackalloc on the caller's stack #9512

Discussion options

You must be logged in to vote

Such code isn't a "correct" implementation and is prone to stack overflow for things like edit controls which can have text longer than what is "safe" to stack allocate.

Beyond that, there isn't really a way to define the state machines (even with ref structs) in a way that allows the scoping and other lifetime requirements of the stack allocation to be properly tracked. It might be possible for the language to add such support, but it would be very complex for a very niche scenario where the alternative results in code that is overall safer, more maintainable, more robust, and more performant.

Such an API should likely be exposed to the consumer as is, with a GetTextLength and a TryGetTe…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@TheLeftExit
Comment options

@tannergooding
Comment options

Answer selected by TheLeftExit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants