Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post Posted: October 13th, 2017, 4:52 pm 
 

Joined: August 12th, 2017, 3:17 am
Posts: 7
Location: Pakistan
What kind of side effect does it bring when i create many classes and object in my program. like a 100 .cpp and 100 .h files. will it effect the framerate of my game or there are some other complications.

Just a silly noob question. :oops: :oops: :oops: :mrgreen:


Top 
 Profile  
Reply with quote  
 Post Posted: October 13th, 2017, 5:27 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2782
Location: Oklahoma, United States
Framerate should not be affected, however, compile time might be lengthened depending on how many of those cpp files need to be compiled.

Your header files (.h) are included in various .h or .cpp files. The compiler will look through each header file that is included. If you don't #include all 100 files in your project, the corresponding .cpp files that you didn't #include their headers, won't be compiled.

If all 100 headers are included and you use a class or function from each one, then it will include the headers and compile all 100 corresponding cpp file. This is why some people choose to forward declare classes or structs in the headers and #include headers only in cpp files when you can. By using this strategy, you can reduce the number of copies of headers to cpp source files. This helps reduce recompile times when something in a header file changes. The reason this works is because when you #include a header in say another header, and that header is #included in yet another header the first header file is also copied in to the last source file.

Code:
FileA.h
class SomeHelperClass{};

FileB.h
#include "FileA.h"
class SomeClass{};

FileC.h
#include "FileB.h"
// Now FileC.cpp has a copy of FileB.h and FileA.h even if FileC.cpp didn't need to know anything about what's in FileA.h.

If the #includes had been in the .cpp files, FileC.cpp would only get a copy of FileB.h which means shorter compile times and possibly smaller compiled program sizes.

Other than that, it shouldn't affect runtime performance having thousands of .h/.cpp files in a project. In the end, the compiler will only compile what it needs and try to optimize out as much as possible.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 2 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: