问题描述
在64位平台上,最好使用8字节长的前缀。如果我们可以处理超过4Gb的内存,为什么不允许5Gb字符串呢?答案是按规范还是有我不知道的一些互操作性/向后兼容性原因?
谢谢。
It seems that on 64-bit platforms it would be reasonable to have a 8-byte length prefix. If we can address more than 4Gb of mem why not allow, say, 5Gb strings? Is the answer just "by specification" or there is some interoperability/backwards compatibility reasons that I'm not aware of?Thanks.
推荐答案
BSTR
数据类型是标准COM字符串数据类型。更改长度前缀将导致无法在不同位数的进程之间安全地移动字符串(或至少使其变得更加复杂)。由于COM是唯一相关的跨位互操作基础结构,因此对于32位进程和64位进程,必须使 BSTR
的行为相同。
The BSTR
data type is the standard COM string data type. Changing the length prefix would make it impossible to safely move strings between processes of different bitness (or at least make it significantly more complex). Since COM is the only relevant cross-bitness interop infrastructure it is necessary to have BSTR
s behave the same way for 32-bit processes and 64-bit processes.
这是一个折衷,施加2GB的限制,以换取不同位的进程之间无障碍的字符串编组。
It is a tradeoff, imposing a 'limit' of 2GB in exchange for hassle-free marshaling of strings between processes of different bitness.
这篇关于为什么在64位平台上BSTR长度前缀为4个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!