NSString对象的最大长度是多少? [英] What is the maximum length of an NSString object?
问题描述
NSString对象中可以保存的最大字符串是多少?
What is the maximum sized string that can be held in a NSString object?
这是否会动态变化?
推荐答案
我认为NSString的硬限制是NSUIntegerMax字符,因为NSString的索引和与大小相关的方法返回NSUInteger。由于目前能够运行iOS的所有设备都是32位,这意味着NSUIntegerMax是2 ^ 32 - 1,NSString可以容纳超过42亿个字符。
I would assume the hard limit for NSString would be NSUIntegerMax characters, since NSString's index and size-related methods return an NSUInteger. Since all devices currently capable of running iOS are 32 bit, this means NSUIntegerMax is 2^32 - 1 and NSString can hold a little over 4.2 billion characters.
其他人有但是指出,实际限制要小得多 - 特别是在iOS设备上,在你达到NSString中的任何硬限制之前很久就会耗尽内存。
As others have pointed out, though, the practical limit is much smaller - on an iOS device especially, you'll run out of memory long before you hit any hard limit in NSString.
这篇关于NSString对象的最大长度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!