out of intrest, why do you want to know the number of ticks?
I''m not convinced this would be a static number anyways depending on how the rest of the pipeline is working and how instructions are being decoded (while not being a compiler theory expert myself its possible that the cpu could start looking up the function pointer to be called before it needs to be called and interlacing other operations around it...)
Cost of Function Pointers (using them)?
quote:Original post by crakinshotDude, you''re missing the point. You don''t need this information. That''s why no one here knows the answer. It does not matter.
hehe... all I asked for in the beginning was the number of ticks... A simple number would of sufficed...
And besides, it''s probably compiler and platform dependant anyway.
someone must know how many ticks it takes... if thats all that he wants someone give it to him..lol
42 ?
As other people pointed out, it depends on the CPU, the state of the pipeline and how the code has been laid out by the compiler.
There is no answer. He could, however, write his own test case and time it himself. This smacks of laziness.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on November 8, 2003 2:33:37 PM]
As other people pointed out, it depends on the CPU, the state of the pipeline and how the code has been laid out by the compiler.
There is no answer. He could, however, write his own test case and time it himself. This smacks of laziness.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on November 8, 2003 2:33:37 PM]
Just do some simple testing... it really shouldn''t be all that complex, and if it''s your only option, you don''t have much of a choice anyways . It''s the most efficient option you''ve got, so not much reason to look for specific speeds, unless you think there are faster/more efficient ways.
You are talking about philosophy!!!
Calling a standard class member function is equal to call every other function (there is a pointer that points to the code...).
With virtual functions the mechanism is the same; the difference is that the compiler insert the code to get a pointer to a function pointer(in the vfptr_table): you have the extra work to get ONE pointer!
If your virtual function does something your overhead will be insignificant...(10%? 5%? 1%?).
Calling a standard class member function is equal to call every other function (there is a pointer that points to the code...).
With virtual functions the mechanism is the same; the difference is that the compiler insert the code to get a pointer to a function pointer(in the vfptr_table): you have the extra work to get ONE pointer!
If your virtual function does something your overhead will be insignificant...(10%? 5%? 1%?).
I imagine a function pointer would be less expensive. With virtual functions each object has a pointer to a table of function pointers, which is used to look up which function to execute, so you have some extra addition and dereferencing.
I agree though, the time needed to do the look up will probably be virtually nothing compared to the time it actually takes the function you're calling to execute, making worrying about it pretty pointless.
[edited by - smart_idiot on November 8, 2003 8:37:14 PM]
I agree though, the time needed to do the look up will probably be virtually nothing compared to the time it actually takes the function you're calling to execute, making worrying about it pretty pointless.
[edited by - smart_idiot on November 8, 2003 8:37:14 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement