Skip to main content
GameDev.net gamedev.net
🔒 Locked

Question about performance

Started by caffeineaddict Apr 28, 2003 at 3:28 PM 3 replies 300+ views
Original Post
caffeineaddict
caffeineaddict
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.
kordova
kordova
Doesn''t the compiler cut and paste the .h files to the main .cpp thus the respective library .c/.cpp files as well?
Russell
Russell
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.

Thunder_Hawk
Thunder_Hawk
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.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.