Fixed
Pinned fields
Click on the next to a field label to start pinning.
Details
Components
Assignee
Gavin HallidayGavin HallidayReporter
Gavin HallidayGavin HallidayPriority
Not specifiedCompatibility
MinorFix versions
Details
Details
Components
Assignee
Gavin Halliday
Gavin HallidayReporter
Gavin Halliday
Gavin HallidayPriority
Compatibility
Minor
Fix versions
Created July 20, 2016 at 10:17 AM
Updated October 10, 2016 at 6:14 PM
Resolved August 10, 2016 at 2:13 PM
There are 3 possible approaches:
If you have the following code:
interface IX : public IInterface { virtual void f(); }; class CX : public CInterface, implement IX { IMPLEMENT_IINTERFACE }
then a call to IX*->f() will generally go through a thunk, which adjusts the this pointer,. and then calls on to main definition. All calls to Link() and Release() will need no thunk
The second case:
class CX : implement IX, public CInterface { IMPLEMENT_IINTERFACE }
This will introduce a thunk for the virtual destructor, but no thunk for f(). It will also pack a following 4 byte number into the space after the link count.
The final version is:
class CX : public CInterfaceOf<IX> { }
This will have no thunks for any of the code, and will reduce the object size by a pointer (8 bytes). (It will also pack a trailing 4 byte member.) It will not be compatible with CInterface, and appears to generate more code than option 2.
So recommendations would be:
i) If an object has large number of instances use CInterfaceOf<X> since the reduction in memory for each object is likely to outweigh any cost.
ii) If the members in an interface are called a large number of times then the second form should be used. Each virtual call will save a sub and a jmp.
iii) otherwise it doesn't matter too much, but the second form is probably to be preferred for new code. Unlikely to be worth going back to change existing definitions though.
@Jacob Cobbett-Smith @Mark Kelly @Richard Chapman FYI