Forum
Question about the Heap - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16)
+---- Thread: Question about the Heap (/showthread.php?tid=465)



Question about the Heap - LCD - 05-30-2012

Hi Boriel, just following easy question:
If I use a heap of 256 bytes, where it is put into memory? I want to know where I cannot put any binary data.
Is this 65535-heapsize?
Edit: May this be problematic if I page the heap out? Is there a possibility that we can put the heap at a selected memory area (e.g. a buffer created with DEFB's) at program start (I know that changing it may crash the program).


Re: Question about the Heap - boriel - 05-30-2012

If you dump your code into asm (--asm), you will see the HEAP is defined JUST after your program. Look for:
Code:
ZXBASIC_MEM_HEAP:
    ; Defines DATA END
ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP + ZXBASIC_HEAP_SIZE
    ; Defines USER DATA Length in bytes
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
The heap is mainly using for STRINGS (at the moment). If you don't use strings you can page it out, do whatever, and page it in back. Another option is to redefine the heap address (two years ago it was allocated BEFORE the program code, but this scheme seemed to be more suitable for re-running the program).
There are many things that can be done, e.g.:
  1. Hack the MALLOC/FREE routine so they will do something like
    1) Remember the current active page (sort of Push PAGE-NUM)
    2) Set a given page (e.g. 5) into memory
    3) Do whatever with the heap
    4) Page out, setting the previous page in 1)
  2. Set the heap again at 28000, or near there.
  3. Set the heap to "FULL" (this can be done by putting 0000h at a given memory location), so any string op will silently fail.



Re: Question about the Heap - LCD - 05-30-2012

Excellent, thank you!
I try to avoid strings and work with memory pointer in my 128K games.
As I do not need much strings, reducing heap and allocating it at a different address is a option. The Printer buffer is large enough, but in 128K BASIC there are system variables stored.
With these informations I'm sure I canfind a solution.


Re: Question about the Heap - boriel - 05-30-2012

I've not finished the "Memory Map" Option yet, but 256 heap bytes might be enough for printing strings for example.
Also you can swap pages for a while with a routine, do something (not using strings) and swap them back and this should work :?:


Re: Question about the Heap - LCD - 05-30-2012

boriel Wrote:Also you can swap pages for a while with a routine, do something (not using strings) and swap them back and this should work :?:
This is the most likely option for me at moment. I'm even sure, I won't use more than 68 bytes in heap. 4700 Bytes is a absolute overkill.