FAQ  •  Register  •  Login

Clarification about HEAP

<<

LukeBord1

Posts: 23

Joined: Sat Jan 17, 2015 9:32 pm

Post Wed Apr 18, 2018 8:49 pm

Clarification about HEAP

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 !?
<<

boriel

Site Admin

Posts: 1540

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu Apr 19, 2018 9:37 am

Re: Clarification about HEAP

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.
<<

LukeBord1

Posts: 23

Joined: Sat Jan 17, 2015 9:32 pm

Post Thu Apr 19, 2018 10:20 am

Re: Clarification about HEAP

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?
<<

boriel

Site Admin

Posts: 1540

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu Apr 19, 2018 11:13 am

Re: Clarification about HEAP

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?
<<

LukeBord1

Posts: 23

Joined: Sat Jan 17, 2015 9:32 pm

Post Thu Apr 19, 2018 12:13 pm

Re: Clarification about HEAP

...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/
<<

boriel

Site Admin

Posts: 1540

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu Apr 19, 2018 1:56 pm

Re: Clarification about HEAP

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.

Return to How-To & Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO