Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Memory used ?
#1
I wonder if there is a way to print the available memory your compile ZX Basic program has used whilst running it?

One more question on memory usage, which would be better in terms of reducing memory overhead?

1) IF WORD$ = "SAVE WORLD" THEN


or
2) IF WORD = 99 and WORD=98 THEN

thanks in advance
Ken
Reply
#2
Hi Ken,

You might be able to work that out from the memory map, which you get with --mmap option. Compile both versions and then compare the memory maps (or, possibly better still, diff the two memory maps). While not everything is immediately obvious, it should be possible to work out the difference.

Hope that helps,
Reply
#3
Yes, I will try this just hoping there was a switch to add that would show memory used on compile but it could grow within the compiled prog so might not be possible.
Reply
#4
You can try to get the memory used within the heap (which is the area for dynamic memory) with the library <alloc.bas>
Code:
#include <alloc.bas>

PRINT memavail()  ' Total HEAP free memory (might be fragmented in 2 or more blocks...)
PRINT maxavail()  ' Size of the largest free contiguous single memory block

On the other hand, if you want to see how memory is organized within a ZX Basic compiled program, use --mmap as @georgeo suggested. :-)
Reply
#5
(03-13-2021, 02:10 PM)RandomiserUsr Wrote: I wonder if there is a way to print the available memory your compile ZX Basic program has used whilst running it?

One more question on memory usage, which would be better in terms of reducing memory overhead?

1) IF WORD$ = "SAVE WORLD" THEN


or
2) IF WORD = 99 and WORD=98 THEN

thanks in advance
Ken

Using numbers will be always faster and shorter. A string is an array of bytes. A number will take 1-2 bytes. This is called "tokenization", and it's used in many text adventures, for example.

To compress text you can also use digraph and trigraph or other compression techniques (search in this forum). ZX Basic will also try to map repeated strings into a single memory region, whenever possible (there's still work to be done on this).
Reply
#6
Hi Boriel,

The <alloc.bas> is very useful. I've overloaded my printing routine, so it also prints the free heap space and maximum contiguous heap space in the corner of the screen. I can see that, with a 4kb heap, my free space hovers around the 4kb mark for most of the time, while my largest allocatable block drops to around 3.5kb over the course of the program.

For my other post, this suggests that the heap space is not the source of my out-of-memory problems ...

Thanks
Reply
#7
(03-14-2021, 12:53 PM)georgeo Wrote: Hi Boriel,

The <alloc.bas> is very useful. I've overloaded my printing routine, so it also prints the free heap space and maximum contiguous heap space in the corner of the screen. I can see that, with a 4kb heap, my free space hovers around the 4kb mark for most of the time, while my largest allocatable block drops to around 3.5kb over the course of the program.

For my other post, this suggests that the heap space is not the source of my out-of-memory problems ...

Thanks

If your heap never drops below 3k, for example, you could set the heap to just 1k and use those remaining 3k for anything else.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)