C ++ Pimpl vs Pure Virtual Interface Performance

I understand that there are quite a lot of messages on this topic, but it is difficult for me to find the answer to this exact question.

For function calls that are faster, a clean virtual interface or pimpl?

At first glance it seems to me that a purely virtual interface will be faster, because using pimpl will cost two function calls instead of one ... or in this case some kind of smart compiler trick will be taken

edit: I am trying to decide which one I should use to abstract the system-dependent parts of several objects, which can end up occurring quite often and in large numbers.

edit
I suppose it’s worth saying that the root of my problem was that I adopted the Abstract Factory design template for a way to make my code work on several platforms when it is really designed to switch implementations for this interface at runtime.

+3
source share
2 answers

The two options are not equivalent, they can not be compared in performance, since the focus is different. Even if they were equivalent, the difference in performance would be minimal and inconsequential in most situations. If you rarely know that sending is a problem, then you have the tools to measure the difference.

+5

? .

: , .

, pimpl, .

. - , , .


, , , , .

, pimpl, , " ". , , .


, , : . "" , , .

, , : , - , , . .

+1

All Articles