Jump to content

C++ Faster loading with classes in the main project file or in another file?

JohanKjeldahl7

Hello there!

 

I am a complete newbie and started with C++ one week ago. I just learned about classes and structures. I know that I can write them before i start my "int main()" and that I can write them into a completely different file and just integrate a link to the new file with my classes before "int main()". My question is: If I had a really big project with really big files, would it be faster if I wrote the classes and so on in the file itself or would it be faster if I write them into a different file and just use the link to the new file? Or would the loading times not be effected enough to notice a difference?

 

I hope this makes sense, as I said I am still a newbie.

Thanks in advance and have a beautiful day!

 

 

But now, fellow gamers, that was it for me. Please keep in mind, that this is just my personal opionion and I am no expert. Your system shall be cooled forever, see you next time.

Link to comment
Share on other sites

Link to post
Share on other sites

Won't make any difference in performance, but everything in one file would be a nightmare to maintain.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Kilrah said:

Won't make any difference in performance, but everything in one file would be a nightmare to maintain.

So it is only used to make the code more "readable"/understandable and reduce the lines of code in a single file?

But now, fellow gamers, that was it for me. Please keep in mind, that this is just my personal opionion and I am no expert. Your system shall be cooled forever, see you next time.

Link to comment
Share on other sites

Link to post
Share on other sites

Yes basically. That way you can organize your code in files dedicated to a specific functionality etc so that you know which file to go in when you're looking for something. 

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, JohanKjeldahl7 said:

So it is only used to make the code more "readable"/understandable and reduce the lines of code in a single file?

Exactly. I mean, if you don't have a very complex project that deliberately compiles into multiple dynamically-loadable files, then all the code in the separate files will still end up in the same executable.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, WereCatf said:

Exactly. I mean, if you don't have a very complex project that deliberately compiles into multiple dynamically-loadable files, then all the code in the separate files will still end up in the same executable.

 

1 minute ago, Kilrah said:

Yes basically. That way you can organize your code in files dedicated to a specific function etc so that you know which file to go in when you're looking for something. 

Okay, that makes a lot more sense to me now. Thank you guys so much!

But now, fellow gamers, that was it for me. Please keep in mind, that this is just my personal opionion and I am no expert. Your system shall be cooled forever, see you next time.

Link to comment
Share on other sites

Link to post
Share on other sites

As others have said multiple files don't actually do anything besides make your code more maintainable. Basically The #include directive actually tells the preprocessor (a compiler component) to copy the text of that file into the target file. From there it is compiled into an object and then the linker links all of your objects together into a cohesive executable file.

 

That's the very brief explanation of what happens. If you want a more detailed explanation this is a good Stack Overflow post on the process. https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, trag1c said:

As others have said multiple files don't actually do anything besides make your code more maintainable. Basically The #include directive actually tells the preprocessor (a compiler component) to copy the text of that file into the target file. From there it is compiled into an object and then the linker links all of your objects together into a cohesive executable file.

 

That's the very brief explanation of what happens. If you want a more detailed explanation this is a good Stack Overflow post on the process. https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work

Thank you!

I will check it out.

But now, fellow gamers, that was it for me. Please keep in mind, that this is just my personal opionion and I am no expert. Your system shall be cooled forever, see you next time.

Link to comment
Share on other sites

Link to post
Share on other sites

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

×