我们什么时候应该使用NSString和NSMutableString? [英] When should we use NSString and NSMutableString?

查看:126
本文介绍了我们什么时候应该使用NSString和NSMutableString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想什么时候应该使用 NSString 我们何时应该使用 NSMutableString ,因为我们可以附加NSString中的字符串也是如此,那么在Objective C编程中有效使用 NSMutableString

I want to when should we use NSString and when should we use the NSMutableString, because we can append the string in NSString also,so what is the effective use of NSMutableString in Objective C programming?

推荐答案

我预计MutableString在内存方面会稍微提高效率,因为你早期指出程序可能需要动态内存。 NSString很可能被分配一个适当大小的内存块。

I expect MutableString will be slightly more efficient in terms of memory as you are indicating early on that the program may need memory dynamically. NSString is likely to be allocated a single, suitably sized block of memory.

使用NSString及其 stringBy ... 方法,您正在创建新对象,释放旧对象(如果需要)并使新对象自动释放。 (如果您从非自动释放更改为自动释放,请注意,您可以在dealloc中发布不再需要的版本)

With NSString and its stringBy... methods, you are creating new objects, releasing the old one (if need be) and making the new object autorelease. (Take care if you are changing from non-autorelease to autorelease, you may have a release in your dealloc that isn't needed anymore)

这篇关于我们什么时候应该使用NSString和NSMutableString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆