Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarification about HEAP
#1
I tried for months to make a compiled intro menu for my Arcade Game Designer projects without success... even storing the compiled menu program in a free memory area (below the AGD code), the game always crashed.

Finally I realized the importance of the HEAP setting in ZXB !
Reading various posts in this excellent forum, Boriel explained that the HEAP setting is a reserved memory area for string variables (please correct me if I'm wrong), and the memory allocation for this parameter is 4768 bytes by default !
So the light turned on and it seems I've finally discovered the cause of the memory collisions...

Since my Basic menu is very simple, including just a couple of UBYTEs without handling any string variable, I tried to set the HEAP to a minimum value like this:
Code:
zxb menu.bas --org=25000 --heap=128
...the magic is done... no crashes and a perfect compiled intro menu for my AGD game!

Now... I just wonder what could be the minimum HEAP setting when there's no string variables at all... and the reason why such an important parameter is just quoted in the ZXB command-line page without any further information !?
Reply
#2
You did right!! 8)
What was happening was an out of memory crash (there's a compiler switch to add tests for that).
The program compiles no heap if no strings are used. :!: So no need to set this to 0.
If you print some string into the screen you're actually using the heap (it depends on some optimizations; the compiler will try not to use it whenever possible).
128 bytes for temporary string management is really small! So better leave it as is. I don't recommend to set this value to something < 128. The heap area starts just after your program to the end of memory.
Reply
#3
Thanks Boriel!
Good to know the heap is used also for the printed strings!
Anyway... i tried to reduce further the heap to 64 and all works perfectly!...

Just for study purposes, here's an excerpt highlighting the strings printed in my Basic menu:
Code:
...
FOR n=2 TO 19: PAUSE 2: PRINT AT n,0;"pppppppppppppppppppppppppppppppp": NEXT: RETURN
PRINT AT 10,5; INK 7; "PRESSpKEYpFORp"; INK 5;"@p"; INK 6; "RIGHT" ...
PRINT AT 10,21; INK 6; "LEFTp" ...
PRINT AT 10,21; INK 6; "DOWN" ...
PRINT AT 10,21; INK 6; "UPpp" ...
PRINT AT 10,21; INK 6; "LASER" ...
PRINT AT 10,21; INK 6; "BOMBp" ...
PRINT AT 10,5; "pppppppppppppppppppp" ...
...
PRINT AT m,11; FLASH 0; OVER 1; INK 8; "pppppppppp" ...        
...
PRINT AT m,11; FLASH 1; OVER 1; INK 8; "pppppppppp" ...
That's all ("p" represents a space)... So, it seems a very low value is good for the heap... thoughts?
Reply
#4
Good again!

For printing constants, the HEAP should not be used, but something like PRINT "HELLO " + a$ is not a constant.
So our program should now use HEAP at all. Which version are you using?
Reply
#5
...I'm currently using the last "stable" v.1.7.2.

Due to the relevance of the above solution for AGD users, i've linked this post to a ZXB tutorial in my site, updating the latest notes :
http://www.funspot.it/boriels-compiler/
Reply
#6
Despite their names, 1.8.3 is the latest 'stable'. Believe me, it's always preferable to move to the latest version. I'm going to change that in the wiki, and add the suffix -beta for every non stable version.
1.8.x fixes tons of bugs and creates better code.

Also that tutorial still uses the old IF syntax. Nowadays the END IF must be removed for single-line ifs.
Reply
#7
Is it possible to find out what heap size a specific program needs and can the compiler be instructed to put it in a specific area in memory instead of the end of the program?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)