Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dealing with "Out of Memory" errors
#1
Hi everyone,

I am relatively new to ZXBASIC, though think I have mostly got the hang of things and am using it to write a new game.

I am seeing intermittent Out of Memory issues (when compiling with --debug-memory), which I believe means I am running out of heap space. However, I've tried increasing the heap quite significantly (e.g., up to 8 kb) with little effect. I've also tried reducing the dependence on string arrays/ variables, in case this was the problem.

If I see an intermittent Out of Memory error mid-way through a program, long after most variables should have been defined, will it be heap-related or could it be something else?

Any suggestions for debugging my code, or properly sizing the heap, would be much appreciated.

Thanks in advance,
Georgeo.
Reply
#2
Hi,
I am new too :-) but what is your compile cmd?
I use this at the moment as my program I writing is heavy on strings

zxbc myprog.bas --tzx --BASIC --autorun --heap=8192 --optimize 2 --org=25000 --debug-memory --debug-array --mmap=memory_%1.txt

Not sure if this helps?
Reply
#3
Hi RandomiserUsr,

Up until now, I've been using something like this:

zxbc --org 26000 -t --strict --debug-memory --heap 6144 -B -a galacticon.bas

--though have tried varying the heap size from 4096 up to 8192 (at the highest level, I get out of memory almost immediately) and also the origin address.

With the above compile command, I get a code block of length 32,628, which I believe includes a 6k heap at the top of the block, so occupies memory 26,000 through to 58,628. I also have some UDGs that are loaded separately to 65,368.

I can't use the --debug-array option as it causes the compiler to crash (I use a pre-existing Python installation, so suspect something isn't quite as required).

The --mmap option looks potentially useful. At least I can see if the extent of the program is as expected.

Thanks,
Reply
#4
Oddly enough I was getting Out Of Memory errors and putting in the debug-memory and debug-arrary I got a Subscript out of range error and
it was correct, I was accessing a higher dimension than there was.

I am using the Windows version and the latest version of zxbc
Reply
#5
Thanks. I've so far been unable to use --debug-array, as it throws a Python error during compilation, which I suspected was because I'd downloaded the platform-independent version and used a separate Python installation. So, I have been trying to check array bounds by hand.

However, fuelled by your feedback, I tried installing a self-contained version of ZXBasic, pre-packaged with Python, on a different computer. Oddly enough I got the same error message, which makes me wonder if it is a problem in my code after all. So, I tried building a simple test program with --debug-array and it worked.

So, now I need to work out why my program can't be compiled with --debug-array. It throws the following error:

Code:
Traceback (most recent call last):
  File "/home/gb/zxbasic/zxbasic/zxbc.py", line 10, in <module>
    sys.exit(libzxbc.main())  # Exit
  File "/home/gb/zxbasic/zxbasic/src/libzxbc/zxbc.py", line 246, in main
    func_visitor.start()
  File "/home/gb/zxbasic/zxbasic/src/arch/zx48k/translator.py", line 1401, in start
    self.visit(f)
  File "/home/gb/zxbasic/zxbasic/src/ast/ast.py", line 35, in visit
    stack.append(last.send(last_result))
  File "/home/gb/zxbasic/zxbasic/src/arch/zx48k/translator.py", line 196, in visit_ARGLIST
    upper = node.parent.entry.bounds[i].upper
  File "/home/gb/zxbasic/zxbasic/src/symbols/boundlist.py", line 29, in __getitem__
    return self.children[key]
  File "/home/gb/zxbasic/zxbasic/src/ast/tree.py", line 40, in __getitem__
    return self._children[key]
IndexError: list index out of range

--though I don't know exactly where this happens in my code.

I'll keep digging. Thanks again,
Georgeo.
Reply
#6
Hi everyone,

I found the bug, which was -- as RandomiserUser guessed -- in my array bounds. Specifically I have  a teletype-style print routine, which looks like:
Code:
sub teletype(p$ as string)
    dim k as uinteger

    printat42(20,1)

    for k=0 to len(p$)-1
        print42(p$(k))
        beep 0.0002,-10
    next k

    BLWindowScrollUp(1,14,30,7)

    return
end sub

Sadly, I didn't spot that this can't cope with an empty string. I think, as k is a uinteger, what I get is a loop from 0 to 65,535 with an empty string, which is entertaining to watch print.

Thanks, Georgeo.
Reply
#7
Nice to see things working for you :-)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)