参考文章:
Unity 游戏的 string interning 优化
C#的字符串优化-String.Intern、IsInterned
http://172.17.144.30:8082/browse/DHR-307
1.优化字符串数量
字符串是不可变的,每次修改字符串都会生成一个新的字符串
即使创建了两个相同的字符串,也会生成2个对象
问题是啥:
1.string创建与销毁的时机
2.是否存在重复的字符串
3.存在没有意义的字符串对象
4.capacity远大于length
5.string泄露
那对于不可变的相同对象,完全是可以复用的
(通过string.Intern)
intern是啥?
举个例子:
string hello = "hello";
string helloWorld = "hello world";
string helloWorld2 = hello + " world";
Debug.Log(helloWorld == helloWorld2);//true
Debug.Log(object.ReferenceEquals(helloWorld, helloWorld2));//false
helloWorld2 = "hello world";
Debug.Log