如何迁移到德尔福2010年和统一code时,也prepare 64位 [英] How to also prepare for 64-bits when migrating to Delphi 2010 and Unicode

查看:149
本文介绍了如何迁移到德尔福2010年和统一code时,也prepare 64位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

64位支持预计不会在未来的版本,它不再是一个选项,以等待可能迁移现有code基地UNI code和一气呵成的64位。 但是这将是很好,如果我们可以做我们的UNI code编译的时候就已经prepare我们code为64位。这将最大限度地减少事件影响,它最终将出现在2020年的版本。 任何建议如何处理这个不引入得多混乱,如果它不到达,直到2020年?

As 64 bits support is not expected in the next version it is no longer an option to wait for the possibility to migrate our existing code base to unicode and 64-bit in one go. However it would be nice if we could already prepare our code for 64-bit when doing our unicode translation. This will minimize impact in the event it will finally appear in version 2020. Any suggestions how to approach this without introducing to much clutter if it doesn't arrive until 2020?

推荐答案

有<一href="http://stackoverflow.com/questions/4051603/64bit-vs-32bit-delphi-applications/4052431#4052431">another类似的问题,但我会重复我的答复在这里,以确保尽可能多的人看到这样的信息:

There's another similar question, but I'll repeat my reply here too, to make sure as many people see this info:

一起来,免责声明:虽然我的Embarcadero公司工作。我不能为我的老板说。我都快写是根据我自己的一个假设64位的Delphi应该如何工作的意见,但也有可能会或可能不会是竞争性的意见和其他预见或不可预见和不兼容导致替代设计决定进行的活动。

First up, a disclaimer: although I work for Embarcadero. I can't speak for my employer. What I'm about to write is based on my own opinion of how a hypothetical 64-bit Delphi should work, but there may or may not be competing opinions and other foreseen or unforeseen incompatibilities and events that cause alternative design decisions to be made.

这是说:

  • 有两种整数类型,NativeInt和NativeUInt,其规模将 32位和64位的系统平台之间浮动。他们已经 周围有不少的版本。没有其他的整数类型将改变大小 根据目标的位数。

  • There are two integer types, NativeInt and NativeUInt, whose size will float between 32-bit and 64-bit depending on platform. They've been around for quite a few releases. No other integer types will change size depending on bitness of the target.

请确保所依靠铸造指针值到任何地方 整数或反之亦然使用NativeInt或NativeUInt的整数 类型。 TComponent.Tag应NativeInt更高版本的Delphi。

Make sure that any place that relies on casting a pointer value to an integer or vice versa is using NativeInt or NativeUInt for the integer type. TComponent.Tag should be NativeInt in later versions of Delphi.

我建议不使用NativeInt或NativeUInt非基于指针的值。尽量保持你的code语义之间的32位和64位是相同的。如果您需要32位的范围内,用整;如果您需要64位,使用的Int64。这样,你的code应该运行在两个bitnesses相同。只有当你在铸造和某种形式的指针值,如引用或THandle,你应该使用NativeInt。

I'd suggest don't use NativeInt or NativeUInt for non-pointer-based values. Try to keep your code semantically the same between 32-bit and 64-bit. If you need 32 bits of range, use Integer; if you need 64 bits, use Int64. That way your code should run the same on both bitnesses. Only if you're casting to and from a Pointer value of some kind, such as a reference or a THandle, should you use NativeInt.

指针状的东西应该遵循类似的规则为指针:对象 引用(明显),而且还像HWND,THandle等。

Pointer-like things should follow similar rules to pointers: object references (obviously), but also things like HWND, THandle, etc.

不要依赖于字符串内部细节和动态数组一样, 它们的头数据。

Don't rely on internal details of strings and dynamic arrays, like their header data.

我们的对64位API的变化总的政策应该是保持 之间的32位和64位,其中有可能,即使这意味着相同的API 64位的API不一定取机器的优点。对于 例如,从TList可能只处理MAXINT格一下SizeOf(指针) 元素,以保持计数,索引等为整数。由于 整型不会浮动(即改变大小取决于位数),我们 不想对客户的code连锁反应:任何索引的 通过一个整数类型的变量,或循环指数往返式操作, 将被截断并可能导致微妙的错误。

Our general policy on API changes for 64-bit should be to keep the same API between 32-bit and 64-bit where possible, even if it means that the 64-bit API does not necessarily take advantage of the machine. For example, TList will probably only handle MaxInt div SizeOf(Pointer) elements, in order to keep Count, indexes etc. as Integer. Because the Integer type won't float (i.e. change size depending on bitness), we don't want to have ripple effects on customer code: any indexes that round-tripped through an Integer-typed variable, or for-loop index, would be truncated and potentially cause subtle bugs.

在哪里的API扩展到64位,他们将最有可能与完成 一个额外的功能/方法/属性来访问额外的数据,这 API也将在32位的支持的。例如,该长度()标准 程序可能会返回整数类型的值参数 输入字符串或动态数组;如果想处理非常大 动态数组,有可能是LongLength()例程为好,其 在32位实现是相同的长度()。长度()将抛出 在64位的一个异常,如果施加到一个动态数组超过232 元素。

Where APIs are extended for 64-bit, they will most likely be done with an extra function / method / property to access the extra data, and this API will also be supported in 32-bit. For example, the Length() standard routine will probably return values of type Integer for arguments of type string or dynamic array; if one wants to deal with very large dynamic arrays, there may be a LongLength() routine as well, whose implementation in 32-bit is the same as Length(). Length() would throw an exception in 64-bit if applied to a dynamic array with more than 232 elements.

与此相关,很可能会提高错误检查 缩小操作中的语言,特别是缩小了64位值 到32位的位置。这将创下分配的可用性 返回长度值类型的整数位置,如果长度() 返回的Int64。另一方面,特别为编译器魔 像长度函数(),可能有截取的魔一些优点, 以如交换机基于上下文的返回类型。但优势无法 同样采取非魔法的API。

Related to this, there will probably be improved error checking for narrowing operations in the language, especially narrowing 64-bit values to 32-bit locations. This would hit the usability of assigning the return value of Length to locations of type Integer if Length(), returned Int64. On the other hand, specifically for compiler-magic functions like Length(), there may be some advantage of the magic taken, to e.g. switch the return type based on context. But advantage can't be similarly taken in non-magic APIs.

动态阵列可能会支持64位索引。需要注意的是Java的 阵列仅限于32位的索引,即使在64位平台。

Dynamic arrays will probably support 64-bit indexing. Note that Java arrays are limited to 32-bit indexing, even on 64-bit platforms.

字符串可能将被限制在32位的索引。我们有一个硬 时间来到了现实的原因,人们希望4GB +字符串 这真的是字符串,而不仅仅是管理的数据的斑点,对于这 动态数组可以用来一样好。

Strings probably will be limited to 32-bit indexing. We have a hard time coming up with realistic reasons for people wanting 4GB+ strings that really are strings, and not just managed blobs of data, for which dynamic arrays may serve just as well.

也许一个内置的汇编,但有限制,比如不能够自由地与德尔福code混合;还有各地需要遵循在x64异常和堆栈帧布局规则。

Perhaps a built-in assembler, but with restrictions, like not being able to freely mix with Delphi code; there are also rules around exceptions and stack frame layout that need to be followed on x64.

这篇关于如何迁移到德尔福2010年和统一code时,也prepare 64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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