zl程序教程

您现在的位置是:首页 >  其它

当前栏目

运行时派发机制

运行 机制
2023-09-11 14:18:45 时间
  • Unlike C++, it is not necessary to designate that a method is virtual in Swift. The compiler will work out which of the following to use: 

    (the performance metrics of course depend on hardware)

    • Inline the method : 0 ns
    • Static dispatch: < 1.1ns
    • Virtual dispatch 1.1ns (like Java, C# or C++ when designated). 
    • Dynamic Dispatch 4.9ns (like Objective-C). 

    Objective-C of course always uses the latter.

https://stackoverflow.com/questions/24022172/does-swift-use-message-dispatch-for-methods/25438321