Memory Use Guidelines
#3
(08-15-2023, 10:18 PM)mnrvovrfc Wrote: 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.
Gotcha, thanks. And best practice to check return values would be, for example,  "IF beep1 > 0 then _SNDPLAY beep1"  every time a sound is played? Or can the checks be done once upon startup?  Or?
Reply


Messages In This Thread
Memory Use Guidelines - by NakedApe - 08-15-2023, 09:22 PM
RE: Memory Use Guidelines - by mnrvovrfc - 08-15-2023, 10:18 PM
RE: Memory Use Guidelines - by NakedApe - 08-15-2023, 10:58 PM
RE: Memory Use Guidelines - by OldMoses - 08-16-2023, 02:24 AM
RE: Memory Use Guidelines - by SMcNeill - 08-16-2023, 05:40 AM
RE: Memory Use Guidelines - by NakedApe - 08-16-2023, 06:57 PM



Users browsing this thread: 3 Guest(s)