How are concatenated strings allocated?
I was wondering how strings and memory work together.
As far as I'm aware, I know that when a string is created, it puts some
array of characters + '\0' into memory. I also know that they're
immutable. So for things like concatenation, what happens in memory that
allows you to access the same string?
I don't imagine that the string or character you concatenated is put
directly after the addresses of the original strings because that might
overlap some needed memory.
In C# and other languages, you can say:
string s = "Hello" ... s = s + '!'
Would this be creating a new string? One that is pointing to a new
location that says "Hello!", leaving the original never to be referenced?
Or is there a default char buffer that strings use that allows for some
space in concatenation?
No comments:
Post a Comment