如何在德尔福工作长度()函数​​? [英] How does the Length() function in Delphi work?

查看:101
本文介绍了如何在德尔福工作长度()函数​​?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 在C ++等其他语言,你必须保持跟踪数组长度自己 - 如何德尔福知道我的数组的长度?是否有一个内部,隐藏的整数?

  • In other languages like C++, you have to keep track of the array length yourself - how does Delphi know the length of my array? Is there an internal, hidden integer?

它是更好,性能的关键部件,不使用长度(),但由我管理的直接整?

Is it better, for performance-critical parts, to not use Length() but a direct integer managed by me?

推荐答案

有三种阵列和长度不同的工作对每个:

There are three kinds of arrays, and Length works differently for each:


  • 动态数组:这些都是实现为指针。指针指向第一个数组元素,但后面该元素(在负从阵列的起始位置的偏移)是重新present阵列的长度和引用计数两个额外的整数值。 长度读取值。这是相同的 string类型。

  • Dynamic arrays: These are implemented as pointers. The pointer points to the first array element, but "behind" that element (at a negative offset from the start of the array) are two extra integer values that represent the array's length and reference count. Length reads that value. This is the same as for the string type.

静态数组:编译器知道数组的长度,所以长度是一个编译时间常数

Static arrays: The compiler knows the length of the array, so Length is a compile-time constant.

打开阵列:开放数组参数的长度作为一个单独的参数传递。编译器知道在哪里可以找到参数,因此它取代长度与该参数的值一读。

Open arrays: The length of an open array parameter is passed as a separate parameter. The compiler knows where to find that parameter, so it replaces Length with that a read of that parameter's value.

这篇关于如何在德尔福工作长度()函数​​?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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