Skip to main content
gamedev.net
🔒 Locked

Functional overloading: Performance hit.

Started by psychic_treason Aug 16, 2001 at 12:11 PM 1 replies 1.2k views
Original Post
psychic_treason
psychic_treason
Okay, another performance related question: I have a function that is overloaded by another. Basically one that is more simple than another [a general case and a specific case if you will]. Now ideally, in the guts of these two functions, I would have the general one work out some details and then pass it to the more specific one [that wouldn''t recalculate anything]. Is there a performance hit to do this?? Or will the compiler unravel it all?? Cheers -- And that''s my $0.02 worth --
Hang on, where I come from, $0.02 is rounded down. Does that mean my opinion is worthless or priceless?
CHROM
-- That's my $0.02 worth --
Hang on, where I come from, $0.02 is rounded down. Does that mean my opinion is worthless or priceless?
CHROM
Grib
Grib
if the simpler function is small enough (in particular few or no conditionals or loops) the compiler may inline the function for you. If you declare the function to be inline, then this is much more likely. There is no way to flat out _FORCE_ the compiler to inline, but you can use a macro if you really don''t trust the compiler, and like to live dangerously.

Note also that a particularly small function that takes a single paramiter, but is called from several places frequently might actually be better when not inline. Remeber a cache miss can take on the order of 10ns(best case). Thats 5-17 cycles, you can do a lot of Push Call Ret Pop''s in that time. Plus you could be passing the paramiter in a register.
danbrown
danbrown
If you mean a straight C/C++ function, the compiler can determine which version of the function should be used at compile time so there won''t be a performance hit. It is when you start using derived classes with overloaded methods that it can''t be determined at compile-time which to use and it will have extra code built in to choose.

Dan
Dan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.