What are the performance implications of marking methods / properties as virtual?

后端 未结 7 1276
别那么骄傲
别那么骄傲 2020-12-04 14:06

Question is as stated in the title: What are the performance implications of marking methods / properties as virtual?

Note - I\'m assuming the virtual methods will <

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 14:32

    Typically a virtual method simply goes through one table-of-function-pointers to reach the actual method. This means one extra dereference and one more round-trip to memory.

    While the cost is not absolutely ZERO, it is extremely minimal. If it helps your program at all to have virtual functions, by all means, do it.

    Its far better to have a well-designed program with a tiny, tiny, tiny performance hit rather than a clumsy program just for the sake of avoiding the v-table.

提交回复
热议问题