Sign in to follow this  

virtual methods

This topic is 2550 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

Hi everyone

I have a very simple question about C++. If you have a class with some virtual methods and non-virtual methods. The dynamic lookup will apply only to the virtual methods of the class. The non-virtual methods will be resolved statically at compilation time i am right ?

Thanks

Share this post


Link to post
Share on other sites
Well, I do not know the answer, but you can find out by compiling code with what you are wondering, and make sure to build the assembly dump with source. Then, look through the assembly to see.

The compiler "SHOULD" be able to figure out a lot and statically link them because not all use of virtual functions are polymorphic function calls. It should be that all "Known" function calls are resolved at compile time, but you should check the assembly to be sure.

Share this post


Link to post
Share on other sites
Thank you for your answers.

For what i have seen, the compiler (some) will be able to go for static call in very simple and almost useless cases like

IInterface *p;

CDeriveredClass x;

p = &x;

In such a case, it knows which class is it.

This isn't much of a performance hit on PC since they have lots of cache. On a console though (PS3 spus have no cache at all), the cache misses and the miss predictions are a big hit.

Also, virtual methods are rarely, if at all, inlined for what i could see.

Thanks again for the answers.

Share this post


Link to post
Share on other sites
Quote:
Original post by Laval B
Thank you for your answers.

For what i have seen, the compiler (some) will be able to go for static call in very simple and almost useless cases like

IInterface *p;

CDeriveredClass x;

p = &x;

In such a case, it knows which class is it.

This isn't much of a performance hit on PC since they have lots of cache. On a console though (PS3 spus have no cache at all), the cache misses and the miss predictions are a big hit.

Also, virtual methods are rarely, if at all, inlined for what i could see.

Thanks again for the answers.


SPU's are a very different kettle of fish. You treat them more like shaders, compile up small subjobs for them todo and spit back data. You only have an limited amount of memory to use in DMA across your data 256KB or something. '

It tends to be a very different type of programming.

Share this post


Link to post
Share on other sites
Quote:
Original post by deepdene
Quote:
Original post by Laval B
Thank you for your answers.

For what i have seen, the compiler (some) will be able to go for static call in very simple and almost useless cases like

IInterface *p;

CDeriveredClass x;

p = &x;

In such a case, it knows which class is it.

This isn't much of a performance hit on PC since they have lots of cache. On a console though (PS3 spus have no cache at all), the cache misses and the miss predictions are a big hit.

Also, virtual methods are rarely, if at all, inlined for what i could see.

Thanks again for the answers.


SPU's are a very different kettle of fish. You treat them more like shaders, compile up small subjobs for them todo and spit back data. You only have an limited amount of memory to use in DMA across your data 256KB or something. '

It tends to be a very different type of programming.



Yes indeed, very different. I think i will use a different approach where more things will be chosen at compile time.

Thanks

Share this post


Link to post
Share on other sites

This topic is 2550 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this