什么是.NET字符串的最大可能长度? [英] What is the maximum possible length of a .NET string?
问题描述
什么是可在.NET创建的最长字符串?该文档的字符串
类没有提及这个问题,据我所看到的,因此,一个权威的答案,可能需要内部的一些知识。请问在64位系统上的最大变化?
What is the longest string that can be created in .NET? The docs for the String
class are silent on this question as far as I can see, so an authoritative answer might require some knowledge of internals. Would the maximum change on a 64-bit system?
[这是要求多为好奇心比实际使用 - !我不打算创建使用巨大的字符串的所有code]
[This is asked more for curiosity than for practical use - I don't intend to create any code that uses gigantic strings!]
推荐答案
的理论极限可能是2,147,483,647,但实际限制是隔靴搔痒的。由于在.NET程序中没有单独的对象可能会超过2GB和字符串类型使用UNI code(2字节每个字符),你可以做的最好的是1,073,741,823,但你不可能永远能够分配一个32位的机器上。
The theoretical limit may be 2,147,483,647, but the practical limit is nowhere near that. Since no single object in a .Net program may be over 2GB and the string type uses unicode (2 bytes for each character), the best you could do is 1,073,741,823, but you're not likely to ever be able to allocate that on a 32-bit machine.
这篇关于什么是.NET字符串的最大可能长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!