Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about the Heap
#1
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).
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#2
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.
Reply
#3
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.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#4
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 :?:
Reply
#5
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.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)