为什么C#/。NET的字符串长度 - prefixed和空终止? [英] Why are C#/.Net strings length-prefixed and null terminated?
问题描述
看完<一href="http://stackoverflow.com/questions/4418708/whats-the-rationale-for-null-terminated-strings">What's对于空的理由终止字符串有的我也发现了类似的问题,在C#/。NET字符串,在内部,无论是长度 - prefixed和空终止像的BSTR数据类型。
After reading What's the rationale for null terminated strings? and some similar questions I have found that in C#/.Net strings are, internally, both length-prefixed and null terminated like in BSTR Data Type.
这是什么原因字符串都是长度 - prefixed和空终止,而不是如。只有长度 - prefixed?
What is the reason strings are both length-prefixed and null terminated instead of eg. only length-prefixed?
推荐答案
长prefixed使计算长度 O(1)
。
Length prefixed so that computing length is O(1)
.
空终止,使编组非托管速度极快(非托管可能希望以空值终止字符串)。
Null terminated to make marshaling to unmanaged blazing fast (unmanaged likely expects null-terminated strings).
这篇关于为什么C#/。NET的字符串长度 - prefixed和空终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!