为什么在 64 位平台上 BSTR 长度前缀为 4 个字节? [英] Why is BSTR length prefix 4 bytes on 64-bit platforms?

查看:18
本文介绍了为什么在 64 位平台上 BSTR 长度前缀为 4 个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎在 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 是唯一相关的跨位互操作基础设施,因此必须让 BSTR 的行为方式与 32 位进程和 64 位进程相同.

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 BSTRs 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 个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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