字符串优化

参考文章:
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值