Hi, may I know how constants are loaded in memory at runtime?
For example, if I have a constant declared in script_1.gd, but this script is never used during a running game, is the constant loaded into a memory address regardless when starting up the game?
If so, if I have a similar constant with the same name declared in script_2.gd, are these taking up two different memory addresses or is Godot able to detect the similarity and only use one address?
I assume you’re talking about consts that look like this:
const TEXTURE = preload("res://texture.png")
If your consts are just int values or something, you don’t need to worry about any of this.
is the constant loaded into a memory address regardless when starting up the game?
No. Constants (and any other dependencies) are only loaded if the script itself is loaded.
similar constant with the same name
The name of the const itself (e.g. const TEXTURE) doesn’t matter.
are these taking up two different memory addresses
All Resource objects loaded from the filesystem are cached by default, meaning that you can preload("res://texture.png") as many times as you want, it will only be loaded once.