Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::function run-time performance

I'm in the process of implementing a platform independent wrapper for dynamically loaded libraries. Of course when I load functions from the libraries I need to store them as pointers for future use. I thought of using boost::function's for that instead of normal function pointers. Sure, that will increase compile time, but that's not what I am afraid of. Rather:

What is the overhead introduced by boost::function when calling the stored function? Is there one? How big is it?

I guess I won't have much overhead when calling such functions from time to time, however, how about functions that get called a lot? (extreme example, glVertex on a loaded GL library). How much would it hurt performance?

Source-diving boost didn't answer much :>.

Also if it's compiler dependant, I'm mainly interested in GCC and MSVC.

like image 550
Kornel Kisielewicz Avatar asked Jan 02 '10 00:01

Kornel Kisielewicz


1 Answers

As stated in the Boost documentation, invoking a boost::function incurs the cost of one call through a function pointer in most cases. In other words, if you were going to have to use function pointers anyhow, it's a wash, and you get a bunch of enhanced functionality for free.

like image 102
Nick Bastin Avatar answered Oct 02 '22 10:10

Nick Bastin