spot
Roslyn String Allocation
I'm interested in seeing exactly how Roslyn allocates strings. I looked through the GitHub a bit, but I couldn't find anything related to my question (Don't know where to look).
First, please help me clear any misconceptions that I may have.
For the following lines of code
What I think I know:
- The C# compiler, Roslyn, will allocate memory for all initialized data.. We are given a memory address for the variable x and the contiguous memory is filled with the UTF character codes for "test".
- x.ToUpper() is (allocated somewhere new? because strings are immutable), "2" is concatenated to the end of it, and then the contents from the new address is copied to the original address of x.
Assuming I used the Debugger to monitor string x or placed in an additional variable to print its address
Would the memory address for x stay the same? (Unless there was not enough contiguous memory to support increasing its length?)
Where can I find the details of this?
Would something like this change between versions of C#? Or is this something that would be decided early on and be relatively consistent through the C# life-cycle? Would this change between different operating systems?
7 replies