Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
suggestion: change to _MEMFREE
#4
_MEM doesn't care what order you free your memory in, just so long as you free them.  And even then, it's really only absolutely necessary when you use _MEMNEW to create a new block of memory.  All the rest of the time, your _MEM variable is just being a pointer to where something already exists.

For example, _MEMIMAGE creates a pointer which lets you access the memory of an image. _MEMFREE won't make that image go away; at most it'll just free up the mem pointer which points to it.  (And you can just reuse that pointer again in the future, with no real worries over it.)

m = _MEM(array()) <-- Same thing.  Nothing more than a pointer to where your array() is stored in memory.  Freeing that mem only frees the pointer.  The array stays just like always, unless you CLEAR/ERASE or do something else with it such as exiting the SUB/FUNCTION it was in.

But when it comes to _MEMNEW, that's when you HAVE to call _MEMFREE.  You allocated a chunk of memory for a block to use, the mem variable is the only pointer which points to that block, and it's the only way you can free that memory.   *ALWAYS* free _MEMNEW blocks when you're done with them -- and you don't have to worry about any order such as "free m1 first, before m2, before m3..."

Think of them much like opening a file.

DIM m as _MEM   <==>   OPEN file$ FOR BINARY AS #m
_FREEMEM m   <==>   CLOSE m

Just like CLOSE doesn't care what order you close your files in, _FREEMEM doesn't care either.  Free them when you get done with them -- especially if they're _MEMNEW blocks.  Wink
Reply


Messages In This Thread
suggestion: change to _MEMFREE - by OldMoses - 12-11-2022, 12:43 PM
RE: suggestion: change to _MEMFREE - by mnrvovrfc - 12-11-2022, 01:03 PM
RE: suggestion: change to _MEMFREE - by OldMoses - 12-11-2022, 01:32 PM
RE: suggestion: change to _MEMFREE - by SMcNeill - 12-11-2022, 01:57 PM
RE: suggestion: change to _MEMFREE - by Pete - 12-11-2022, 05:52 PM
RE: suggestion: change to _MEMFREE - by OldMoses - 12-11-2022, 07:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Feature Request: Limit Scope of a "Find" and "Change" hanness 5 741 06-21-2025, 11:21 PM
Last Post: SMcNeill
  _SndRaw and _MemFree Petr 1 580 01-11-2025, 09:04 PM
Last Post: a740g
  Odd behavior with Search -> Change window TerryRitchie 8 1,581 05-09-2024, 05:00 PM
Last Post: bplus
  Suggestion: Preallocated file open doppler 14 2,812 02-25-2024, 02:35 AM
Last Post: SMcNeill
  suggestion: create a custom puppy linux distro that includes QB64PE out of the box madscijr 13 2,856 02-07-2024, 02:25 PM
Last Post: TerryRitchie

Forum Jump:


Users browsing this thread: 1 Guest(s)