Вопрос

Will registering functions in a TdwsUnit yield the same performance as regular magic functions such as those registered in the dwsMathComplexFunctions.pas unit?

Это было полезно?

Решение

Usually no, because TdwsUnit functions and methods's OnEval event gets the full comfortable & safe treatment:

  • call parameters are evaluated and pushed on the stack
  • a TProgramInfo/IInfo context is made accessible so you get comfortable access to variables by name, and can in turn call everything else in the script comfortably
  • your execution is protected by an exception frame

By contrast, magic functions get none of that: they just get a list of expressions for the parameters, and that's all. No stack context, no easy access to anything else, so it's up to you to evaluate the parameters and handle everything. That makes them more suitable for simple tasks that will need to happen fast.

Note that incrementally, in addition to OnEval, some functions in TdwsUnit are now getting an OnFastEval event, which is an alternate way to declare a magic function.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top