Does .net sting class support cache/pool mechansism to reduce allocation overhead?
Does .net sting class support cache/pool mechansism to reduce allocation overhead?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
String literals are interned, if that’s what you’re talking about:
Both
aandbare guaranteed to be true.You can call
string.Internyourself, too.However as far as normal strings go (for example, the string object returned by
string.Format), the answer would be no, they’re not cached by default. But you could either create your own cache or intern them if you absolutely must. As many strings are short-lived, I suspect that in most cases it’s not worth caching.