Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_mem
#6
(01-01-2025, 10:01 AM)Jack Wrote: it's clear that the memory allocated to the string s is being addressed, so why do I need to free m which behaves as a pointer to s ?

Because m, itself, is really nothing more than a handle of sorts (unless used with _MEMNEW), and just like _LOADIMAGE creates handles endlessly, _MEM will as well.   In the case of mem, each handle uses ... umm..  I'd guess 100 bytes of memory?  (I'd have to look at the types and such to be certain, so let's just sy it's a hundred bytes at 5 in the morning and call it close enough. Tongue )

So inside a loop where you call something like:

SUB foo (x AS LONG)
   DIM m AS _MEM
   m = _MEM(x) 
END SUB

That is going to use 100 bytes every time its called to create that handle with all its reference info, and you're never going to be able to free it until the program ends.

Call it a thousand times, you now have 100,000 bytes of memory tied up doing nothing that you can never free...  Call it inside a game loop which repeats 60 times a second, and what's going to happen to your memory usage after 4 hours of playing the same game?  

KABOOM!!  Out of memory!
Reply


Messages In This Thread
_mem - by Jack - 12-31-2024, 09:52 PM
RE: _mem - by DSMan195276 - 01-01-2025, 07:11 AM
RE: _mem - by Jack - 01-01-2025, 09:08 AM
RE: _mem - by Jack - 01-01-2025, 10:01 AM
RE: _mem - by SMcNeill - 01-01-2025, 10:18 AM
RE: _mem - by SMcNeill - 01-01-2025, 10:10 AM
RE: _mem - by Jack - 01-01-2025, 10:27 AM
RE: _mem - by SMcNeill - 01-01-2025, 10:36 AM
RE: _mem - by Jack - 01-01-2025, 10:40 AM
RE: _mem - by SMcNeill - 01-01-2025, 10:45 AM
RE: _mem - by Kernelpanic - 01-01-2025, 11:55 PM
RE: _mem - by DSMan195276 - 01-01-2025, 11:13 PM
RE: _mem - by DSMan195276 - 01-02-2025, 12:27 AM



Users browsing this thread: 8 Guest(s)