Author Topic: Memory Leak with Axe sub( ?  (Read 4821 times)

0 Members and 1 Guest are viewing this topic.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Memory Leak with Axe sub( ?
« on: May 31, 2011, 02:08:56 pm »
Suppose I had the following code (basically an endless loop):

Lbl A
sub(B

Lbl B
Goto A

Is this bad?

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Memory Leak with Axe sub( ?
« Reply #1 on: May 31, 2011, 02:13:23 pm »
Yes, it's bad. It'll cause a stack overflow, and then random things start happening because data is being executed.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Memory Leak with Axe sub( ?
« Reply #2 on: May 31, 2011, 05:12:50 pm »
Code: (Axe) [Select]
Lbl A
sub(A)

Same thing :D

sub( is basically just CALL. That's all it is.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Memory Leak with Axe sub( ?
« Reply #3 on: May 31, 2011, 06:09:06 pm »
Code: (Axe) [Select]
Lbl A
sub(A)

Same thing :D

sub( is basically just CALL. That's all it is.

So that's not like Pause 0, it's really infinite or does it break or something?

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Memory Leak with Axe sub( ?
« Reply #4 on: May 31, 2011, 07:39:46 pm »
Its okay if you have a base case and you've set it up to be a recursive call.  For instance, you could write a factorial function like this:

Code: [Select]
Lbl A
If r1=0
  Return 1
End
Return r1*sub(A,r1-1)

Anyway you just have to be careful about those.  The less goto's you have in your code, the less likely you will leak.  Most uses of Goto can be replaced by either loops or subroutines without sacrificing speed or size.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Memory Leak with Axe sub( ?
« Reply #5 on: May 31, 2011, 08:02:04 pm »
Code: (Axe) [Select]
Lbl A
sub(A)

Same thing :D

sub( is basically just CALL. That's all it is.

So that's not like Pause 0, it's really infinite or does it break or something?

Pause is really a bunch of jumps (DJNZ and JR, to be exact). sub( is different because it's CALL, which uses the stack. You know what happens when you overload the stack ;)




Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Memory Leak with Axe sub( ?
« Reply #6 on: May 31, 2011, 08:18:45 pm »
I also found Asm(3333 to work :P

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Memory Leak with Axe sub( ?
« Reply #7 on: May 31, 2011, 11:00:37 pm »
I also found Asm(3333 to work :P
Yeah, randomly increasing the stack pointer does seem to have that affect.

And compiling the "Lbl A:Sub(A)" thing shows that it is in fact, just a straight call back to 9D95.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Memory Leak with Axe sub( ?
« Reply #8 on: May 31, 2011, 11:30:20 pm »
I also found Asm(3333 to work :P
Yeah, randomly increasing the stack pointer does seem to have that affect.

And compiling the "Lbl A:Sub(A)" thing shows that it is in fact, just a straight call back to 9D95.

Lol, I meant increasing the stack pointer fixes the problem

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Memory Leak with Axe sub( ?
« Reply #9 on: June 01, 2011, 03:20:45 pm »
I also found Asm(3333 to work :P
Yeah, randomly increasing the stack pointer does seem to have that affect.

And compiling the "Lbl A:Sub(A)" thing shows that it is in fact, just a straight call back to 9D95.

Lol, I meant increasing the stack pointer fixes the problem
Oh, right, stack grows downward. This is why I can never really be a great z80 coder.  I can't remember stupid details like that!

Offline BrownyTCat

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 420
  • Rating: +37/-8
    • View Profile
Re: Memory Leak with Axe sub( ?
« Reply #10 on: June 02, 2011, 12:26:36 pm »
I hear "Memory leak" a lot and generally know what it is on computers, but is it permanent memory loss on Z80 calculators?

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Memory Leak with Axe sub( ?
« Reply #11 on: June 02, 2011, 12:52:32 pm »
I hear "Memory leak" a lot and generally know what it is on computers, but is it permanent memory loss on Z80 calculators?

When you are programming for calculators (actually for anything, but calculators in particular), you require memory for loops and subprograms.  The more unexited loops and subgrams you are running at once the more memory you need.  Eventually you reach a point where you run out of safe-to-use memory.  You don't lose the memory for good, but your calculator does crash or can't run anymore.
« Last Edit: June 02, 2011, 12:53:24 pm by Hot_Dog »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Memory Leak with Axe sub( ?
« Reply #12 on: June 02, 2011, 01:03:21 pm »
Depends on the context. In BASIC a "memory leak" (caused by Goto'ing out of a loop) causes a minor leak that is returned when the program exits. In Axe and ASM, a memory leak is a bit more serious, but it still doesn't usually crash or anything. It just means a small portion of your RAM is unavailable because your calculator thinks it's still being used, and it gets fixed when you RAM clear. But in this case, if you keep using sub( (or CALL) over and over, you cause a type of memory leak that could lead to a stack overflow, which finishes off in a nice little crash. None of it's permanent, though.