Author Topic: How big is memory block after _MEMFREE?  (Read 3844 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
How big is memory block after _MEMFREE?
« on: October 17, 2021, 05:03:29 am »
Hi. Is this output correct? I think, after _MEMFREE is expected output zero?

Code: QB64: [Select]
  1. Dim As _MEM l, r
  2. l = _MemNew(50000000)
  3. r = _MemNew(50000000)
  4. Print l.SIZE, r.SIZE
  5. Print "Size after MEMFREE:"; l.SIZE, r.SIZE
  6. l = _MemNew(10000)
  7. r = _MemNew(10000)
  8. Print l.SIZE, r.SIZE
  9.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: How big is memory block after _MEMFREE?
« Reply #1 on: October 17, 2021, 07:58:53 am »
I guess the memory is freed, but the variable pointer still contains data until it is reassigned.

Code: QB64: [Select]
  1. DIM AS _MEM l, r
  2. l = _MEMNEW(50000000)
  3. r = _MEMNEW(50000000)
  4. PRINT l.SIZE, r.SIZE
  5. PRINT "Size after MEMFREE:"; l.SIZE, r.SIZE
  6. l = _MEMNEW(10000)
  7. r = _MEMNEW(10000)
  8. PRINT l.SIZE, r.SIZE
  9.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: How big is memory block after _MEMFREE?
« Reply #2 on: October 17, 2021, 10:18:42 am »
Quote
I guess the memory is freed, but the variable pointer still contains data until it is reassigned

Maybe, but is this so correct? I can't imagine using CLEAR other than at the end of the program before the SYSTEM statement.
I look to IDE Help and find _MEMEXISTS, so _MEMEXIST replaces this feature (if write to program something  as IF L.SIZE THEN... or if is used IF _MEMEXISTS(L)THEN... so it doesn't really matter. I just have to remember that the first method is not reliable.

FellippeHeitor

  • Guest
Re: How big is memory block after _MEMFREE?
« Reply #3 on: October 17, 2021, 10:21:21 am »
Like OldMoses said it, the memory is freed, but the variable isn't cleared. The same happens with _LOADIMAGE and _SNDOPEN, for example. They all return a handle, but calling _FREEIMAGE or _SNDCLOSE won't zero the handle variable, although the memory used by the resources does indeed get freed.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: How big is memory block after _MEMFREE?
« Reply #4 on: October 17, 2021, 10:32:38 am »
Quote
Like OldMoses said it, the memory is freed, but the variable isn't cleared. The same happens with _LOADIMAGE and _SNDOPEN, for example. They all return a handle, but calling _FREEIMAGE or _SNDCLOSE won't zero the handle variable, although the memory used by the resources does indeed get freed.

@FellippeHeitor
Thanks for confirming information by @OldMoses  I will remember it. I hope so. :)

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: How big is memory block after _MEMFREE?
« Reply #5 on: October 17, 2021, 11:45:35 am »
I can't imagine using CLEAR other than at the end of the program before the SYSTEM statement.

Neither can I, in fact, this is about the only time I've ever used it. Given that those are the only two variables in the code, and CLEAR doesn't effect the previous static DIMing of them, I considered it the easiest way to null them.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How big is memory block after _MEMFREE?
« Reply #6 on: October 17, 2021, 12:19:15 pm »
@Petr "How big is memory block after _MEMFREE?" - I forget.

Kidding aside, like the other post confirmed, and QBasic was the same, which had the nice feature of the FRE() statement to check on memory usage.

@OldMoses I used to use CLEAR in QB. It worked great as a way to avoid using RUN to rerun a program. It was also a great way to zero all your variables, without creating a variable clearing routine. That was a perfect keyword for a run and gun programmer like me. I never kept track of my variable usage, and used hundreds of them for my largest apps. As for now? Now I avoid CLEAR; because unless it got a makeover in V2.0 (sorry, I haven't read the change log info yet), CLEAR in QB64 always failed to act properly. The same is (was?) true for the QB64 RUN statement. I'd like to mention what all those problems are (were?). One I believe was not resetting VIEW PRINT, and I think there were one or two others. It's just at my age, I tend to forget or conflate things. Not as bad as Joe Biden, and his orange complexion and gold colored hair, but then I didn't start out dumb as a stump and crooked as the tree that used to be there.

Pete :D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/