Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Memory Use Guidelines
#2
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.
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  computer vision? capture still from webcam to memory & identifying colors & pixels? madscijr 0 428 02-25-2025, 06:16 PM
Last Post: madscijr
  A Question on memory set aside for Zero Dimster 11 1,814 12-01-2024, 04:01 PM
Last Post: SMcNeill
Question Memory full when loading multiple images Ikerkaz 7 1,576 11-03-2024, 05:51 PM
Last Post: bplus
  Loading font from memory help needed... Dav 6 1,413 09-16-2023, 04:03 PM
Last Post: SMcNeill
  Memory Leak NasaCow 12 2,616 05-11-2023, 03:43 PM
Last Post: TerryRitchie

Forum Jump:


Users browsing this thread: 1 Guest(s)