Performance of std::function compared to raw function pointer and void* this?

前端 未结 3 1962
心在旅途
心在旅途 2020-12-09 19:25

Library code:

class Resource 
{
public:
    typedef void (*func_sig)(int, char, double, void*);
//Registration
    registerCallback(void* app_obj, func_sig f         


        
3条回答
  •  眼角桃花
    2020-12-09 19:47

    std::function performs type erasure on the function type and there is more than one way to implement it, so you maybe should add which version of which compiler you are using to get an exact answer.

    boost::function is largely identical to a std::function and comes with an FAQ entry on call overhead and some general section on performance. Those give some hints on how a function object performs. If this applies in your case, depends on your implementation but numbers shouldn't be significantly different.

提交回复
热议问题