Archived

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

caffeineaddict

Question about performance

Recommended Posts

caffeineaddict    633
I was just curious about one thing, is there any performance difference if you write different modules and have each in a different cpp file or if you have everything in 1 file. I know that having everything in 1 file is unfeasible for large projects, just curious.

Share this post


Link to post
Share on other sites
Russell    118
quote:
Nope. No performance difference.
That is not entirely true. With most compilers, a function can only be inlined if the calling file can "see" the function. If the function is in another file, it gets linked, and the calling file can''t see that function directly. I think the .NET compiler will let you inline from an external source file, which solves this problem.
quote:
Doesn''t the compiler cut and paste the .h files to the main .cpp thus the respective library .c/.cpp files as well?
The header files basically get cut and paste, but not the source files (.c, .cpp). The source files get compiled seperately into object files, and then the linker links the object files and makes one executable. This is the main reason why you cannot inline a function that is implemented in another source file. Newer compilers will probably start allowing broader inlining in the future.

Share this post


Link to post
Share on other sites
Thunder_Hawk    314
This is also why templates are often glued to the header file. It''s kind of hard to generate a specialized function/class with out the information needed to do it. This too is planned to be changed in the future.

Share this post


Link to post
Share on other sites