Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Speed of various function calls...

This topic is 6309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was just wondering how function calls works? More specifically member functions(from class), pointer function calls, namespace function calls, and overloaded function calls. The things that I want to know whats invovled is the exact scenario of things like first the function is located, next the value paramters are copied...and so and so. Help would be appreciated. Thanks. "Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.

Share this post

Link to post
Share on other sites
Brief synopsis that applies in most cases:
1) Arguments are pushed onto stack or loaded into registers (or both) The address of the next instruction is also pushed so that you can ''return''

2) A call is made that basically jumps execution to the function which uses the pushed/registered values.

3) Everything is popped back off the stack and execution jumps back to the next instruction in the previous line of execution.

This is how virtually every function call works. Member functions just have an additional hidden argument (this) that is sent along as well.

The only real difference is virtual functions. In these cases, the exact jump to make is looked up in a table first and then the jump is made.

Namespaces and overloaded functions can just be considered normal functions with different names. For example, the function:
MyClass::func(int a)
might be represented by the compiler as
in order to make the name unique.
This is called ''name decoration''. Of course, most compilers do a lot more decorating including GUIDS and more info like return types, this is just an example

Well, I hope I helped you out a little. I unfortunately, don''t have the time for a more in depth explanation at the moment.

Share this post

Link to post
Share on other sites
Functions in a namespace and overloaded functions work just like any other function. All of there special features are handled during compilation. Member functions are called just like normal except that the ecx register holds the this pointer to the class (in MSVC, some other compilers do it differently). Function pointers take two steps: get the pointer''s value, then call it, so they''re the slowest of those choices (but still pretty fast, and better than a switch each time to determine the function to call).

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
also when a function parameter happens to be a class, its copy constructor will get called if you are passing it by value.
if this function gets called hundreds of times per frame,
that copy constuctor can get very expensive. it usually best
to pass classes by reference (a pointer to it or an address) instead of by value.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!