How does the Length() function in Delphi work?

后端 未结 5 1648
太阳男子
太阳男子 2020-12-31 13:32
  • 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

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 14:07

    Don't forget that the layout of dynamic arrays and the like would change in a 64-bit version of Delphi, so any code that relies on finding the length at a particular offset would break.

    I advise just using Length(). If you're working with it in a loop, you might want to cache it, but don't forget that a for loop already caches the terminating bounds of the loop.

提交回复
热议问题