08-15-2023, 10:18 PM
Allocate only the fonts, images and sounds that you need. Do not do it in a loop.
For example, do not switch fonts only by calling _LOADFONT. It's a huge shocking waste. It's only necessary to use _LOADFONT once to get a handle and save it to a LONG variable, then use _FONT to switch to that font.
Try to keep images small and sounds short. It doesn't matter what is the format of an audio file, the PCM data requires a lot of RAM. If the original was 22050Hz sampling rate or less, it is converted by QB64 to 44100Hz or maybe even 48kHz depending on the system QB64 is running in, which requires more memory. Load only one background image for a 4k screen because this rule about RAM might apply also to images. 32-bit images generally require more memory than those with 16 or 256 colors.
Always check the return values of _LOADFONT, _LOADIMAGE and _SNDOPEN. If not, it could cause memory leaks. It could be helpful to use _FILEEXISTS before one of those other functions to make sure a resource is found on disk. If not your program could crash unexpectedly to a runtime error box. QB64 could be a bit unpredictable about this. Sometimes it doesn't like a font. There's no choice but to use another one. Sometimes you have to give more parameters to _LOADIMAGE so an image is loaded at all, or it's loaded at the highest quality possible.
For example, do not switch fonts only by calling _LOADFONT. It's a huge shocking waste. It's only necessary to use _LOADFONT once to get a handle and save it to a LONG variable, then use _FONT to switch to that font.
Try to keep images small and sounds short. It doesn't matter what is the format of an audio file, the PCM data requires a lot of RAM. If the original was 22050Hz sampling rate or less, it is converted by QB64 to 44100Hz or maybe even 48kHz depending on the system QB64 is running in, which requires more memory. Load only one background image for a 4k screen because this rule about RAM might apply also to images. 32-bit images generally require more memory than those with 16 or 256 colors.
Always check the return values of _LOADFONT, _LOADIMAGE and _SNDOPEN. If not, it could cause memory leaks. It could be helpful to use _FILEEXISTS before one of those other functions to make sure a resource is found on disk. If not your program could crash unexpectedly to a runtime error box. QB64 could be a bit unpredictable about this. Sometimes it doesn't like a font. There's no choice but to use another one. Sometimes you have to give more parameters to _LOADIMAGE so an image is loaded at all, or it's loaded at the highest quality possible.