Posted: 6th Apr 2024 20:43
#include "agk.h" includes all header files for AppGameKit commands and it is necessary to put it into all .cpp files where AppGameKit commands are needed. My question is: Do these inclusions make the final .exe larger or do they increase the memory usage during game runtime? Or are these source files compiled multiple times?
This is more like a general C++ question, but I wonder if I should be careful with including the same header files, or if this is nothing to worry about at all. I use Visual Studio.
Thanks for all replies.
Posted: 7th Apr 2024 3:07
The headers will only be loaded once. There would be massive amount of errors if the headers were loaded and compiled each time they are called. Also most modern compilers should optimize the way they compile with the headers. The linking of the lib file will really be what sets the size of the exe file that is what the headers are giving you access to. But the headers have code at the top of the headers that detect whether it is already loaded so you really don't have to worry about agk's tier 2 headers.
Posted: 7th Apr 2024 4:01
For this we use "include guards"

if you look in the agk.h file you will see the code is wrapped in the following compiler directive

+ Code Snippet
#ifndef _H_AGK_ 
#define _H_AGK_

// code in here only loads once

#endif


This is a compiler safe include guard, ie: will work in all compilers

when you create a header in VS it adds

+ Code Snippet
#pragma once


This does exactly the same thing but is not compatible with all compilers, if you only use VS then this is good enough

using either ensures that the header file is only compiled into the project once, without these guards as Dark Raven said you would get a long list of redeclaration errors.
Posted: 7th Apr 2024 14:44
OK guys, now I understand it more.
Thank you for your help!