Menu

Memory issues in GW basic

2015-09-11
2020-04-12
  • John Brzorad

    John Brzorad - 2015-09-11

    I am getting "out of memory" errors when I am running a gw-basic program. I have 8 variables that I have bumped up in my dim statements up to dim a(2500). Also I have a for next loop with 13,000 loops. Is there a way to add memory? I am running on a 32-bit computer. Could switching to my lap top (64-bit) make any difference? Should I use a different language?

     
  • Rob Hagemans

    Rob Hagemans - 2015-09-11

    Hi John!

    PC-BASIC tries to emulate GW-BASIC as closely as possible, which means its internal addressing and representation of variables is the same. Sadly that means a 64KiB limit on data, as GW-BASIC uses 16-bit pointers to address its variables (see e.g. the VARPTR functions).

    You can get a bit more memory by using the option --reserved-memory=0 but to be honest the difference isn't huge (you gain about 3K). Unfortunately, switching to a 64-bit computer will not make a difference.

    In your case, I understand you use 8 arrays of 2500 entries. If you declare them as DIM A(2500) they will be single-precision floats, which take 4 bytes each; you'd need 80K which is indeed too much.

    If your variables are whole numbers in the range [-32768, 32767], you could consider declaring ints: DIM A%(2500), which use only 2 bytes each; 8*2500*2=40K should fit.

    I've had requests before to open up the memory limit, as indeed 64K is a bit silly on computers with 8G RAM and more, and I may well implement something in future (disabling POKE, VARPTR, etc. and enabling more storage) but for now there is still too much to do to get the GW-BASIC emulation to where I want it to be, so it will not be soon.

    As for other languages you could use, I find Python very suitable for the sort of scripting and file editing you mentioned in your earlier post, and indeed for larger projects (PC-BASIC is written in Python).

    Rob

     
  • Anonymous

    Anonymous - 2015-09-11

    Thanks so much, Rob!
    My variables are UTM coordinates and not only do I create grids (each with x,y points) with 30K plus points, but I am also reading in large arrays of individual points (actually bird locations gleaned from GPS transmitters). As many of my digits are redundant (e.g. x=638712(an easting)) can be reduced to 42 without loosing its meaning. I will try reducing these digits and if that does not work, ....I suppose I am learning python :) Thanks again
    Cheers
    Johnnyb

     
  • Rob Hagemans

    Rob Hagemans - 2015-09-12

    Perhaps you don't need to have everything in memory at the same time; if that's the case you could work on one coordinate at a time and run through a file, avoiding the memory issues.

    That said, you may prefer a platform that actually makes use of your computer's capabilities :) I like Python, it's powerful and easy to get into... but of course it does take some time learning it, so you could also check out FreeBasic,
    QB64 or SmallBASIC. They're all free BASIC implementations more or less based on QuickBASIC syntax. While I haven't really worked with them, I get the impression that you should be able to use GW-BASIC programs with only minor modifications.

     
  • Cedric T Jemison

    I'm marking a program that suppose to eliminate a number at a time, but when I run this program, it says:
    LIST 1-100
    10 RANDOMIZE
    20 LET A=1: B=2: C=3: D=4: E=5: F=6: G=7: H=8: I=9
    30 PRINT
    40 PRINT "ROLLER BOARD"
    50 PRINT USING " # # # # #";A;B;C;D;E
    60 PRINT USING " # # # # ";F;G;H;I
    70 PRINT
    80 LET D1=INT(9*RND(1))+1
    90 PRINT "YOU ROLLED A ";D1
    100 PRINT
    Ok
    RUN
    Random number seed (-32768 to 32767)? 489
    Out of memory in 20 (I can't continue writing this program after line 6690)
    Ok
    It's a long program and it always happen when I program it to eliminate the 5th number. My goal is to eliminate all nine numbers to win the game anything short of that will end the game. You cannot remove the same number that you already eliminated. So I don't know what's wrong with line 20. It's no math involve just a series of conditions using AND/OR Statements with ()

    6640 IF (D5>5 AND (D4=2 OR D4=4) AND (D3=2 OR D3=4) AND D2>5 AND D1>5) OR (D5>5 AND (D3=2 OR D3=4) AND (D2=2 OR D2=4) AND D1>5 AND D4>5) THEN PRINT USING " # # #";A;C;E
    6650 IF (D5>5 AND (D2=2 OR D2=4) AND (D1=2 OR D1=4) AND D4>5 AND D3>5) OR (D5>5 AND (D1=2 OR D1=4) AND (D4=2 OR D4=4) AND D3>5 AND D2>5) THEN PRINT USING " # # #";A;C;E
    6660 IF (D5=2 AND D4=4 AND D3>5 AND D2>5 AND D1>5) OR (D5=2 AND D3=4 AND D2>5 AND D1>5 AND D4>5) OR (D5=2 AND D2=4 AND D1>5 AND D4>5 AND D3>5) OR (D5=2 AND D1=4 AND D4>5 AND D3>5 AND D2>5) THEN PRINT USING " # # #";A;C;E
    6670 IF (D5=4 AND D4=2 AND D3>5 AND D2>5 AND D1>5) OR (D5=4 AND D3=2 AND D2>5 AND D1>5 AND D4>5) OR (D5=4 AND D2=2 AND D1>5 AND D4>5 AND D3>5) OR (D5=4 AND D1=2 AND D4>5 AND D3>5 AND D2>5) THEN PRINT USING " # # #";A;C;E
    6680 IF (D5>5 AND (D4=2 OR D4=5) AND (D3=2 OR D3=5) AND D2>5 AND D1>5) OR (D5>5 AND (D3=2 OR D3=5) AND (D2=2 OR D2=5) AND D1>5 AND D4>5) THEN PRINT USING " # # # ";A;C;D
    6690 IF (D5>5 AND (D2=2 OR D2=5) AND (D1=2 OR D1=5) AND D4>5 AND D3>5) OR (D5>5 AND (D1=2 OR D1=5) AND (D4=2 OR D4=5) AND D3>5 AND D2>5) THEN PRINT USING " # # # ";A;C;D
    But i can run this program up to this point:

    RUN
    Random number seed (-32768 to 32767)? 276

    ROLLER BOARD
    1 2 3 4 5
    6 7 8 9

    YOU ROLLED A 2

    UPDATED BOARD
    1 3 4 5
    6 7 8 9

    PRESS <enter> TO ROLL THE DICE...? (2nd Roll)
    YOU ROLLED A 4 </enter>

    UPDATED BOARD
    1 3 5
    6 7 8 9

    PRESS <enter> TO ROLL THE DICE...? (3rd Roll) </enter>

    YOU ROLLED A 9

    UPDATED BOARD
    1 3 5
    6 7 8

    PRESS <enter> TO ROLL THE DICE...? (4th Roll)
    YOU ROLLED A 1 </enter>

    UPDATED BOARD
    3 5
    6 7 8

    PRESS <enter> TO ROLL THE DICE...? (5th Roll)
    YOU ROLLED A 3 </enter>

    UPDATED BOARD
    6 7 8
    7 8
    6 8
    6 7
    Ok
    THE UPDATED BOARD suppose to show:
    5
    678

    But because I can't write any further on this program without the out of memory error, I not sure my program will allow me to finish when it eventually has no numbers left.

    A different run of program:
    RUN
    Random number seed (-32768 to 32767)? 843

    ROLLER BOARD
    1 2 3 4 5
    6 7 8 9

    YOU ROLLED A 6

    UPDATED BOARD
    1 2 3 4 5
    7 8 9

    PRESS <enter> TO ROLL THE DICE...?
    YOU ROLLED A 6 </enter>

    NUMBER 6 IS ALREADY OFF THE BOARD.
    BAD ROLL...YOU LOSE!!!
    Ok

     
    • Marc 'BlackJack' Rintsch

      Oh dear, please tell me you are not coding each roll and each possible outcome sequentially with all those IFs. And if you do, then this must be to kill time because you are stuck at home because of the corona virus and are bored beyond imagination. 😮

      Here's that thing in 10 lines of code:

      10 RANDOMIZE:NC=9:RC=0:DIM B(NC):FOR I=1 TO NC:B(I)=-1:NEXT
      20 R=0:FOR I=1 TO NC:R=R OR B(I):NEXT:IF NOT R THEN GOTO 100
      30 PRINT"Board":FOR I=1 TO NC:IF B(I) THEN PRINT I;
      40 NEXT:PRINT:PRINT
      50 RC=RC+1:PRINT"Press <enter> to roll the dice. (";RC;". roll)";:INPUT A$
      60 D=INT(NC*RND(1))+1:PRINT"You rolled a";D
      70 IF B(D) THEN B(D)=0:GOTO 20
      80 PRINT"Number";D;"is already off the board."
      90 PRINT"Bad roll. You loose.":END
      100 PRINT"Board is empty. You win.":END
      
       
      • Cedric T Jemison

        Wow only 10 lines of code. I'm shocked!!! I was trying set up this program so I can eventually do the high rollers game by using two dices and give the user an option to eliminate a single number or multiple numbers at a time. Then the user can roll a second time. As long the number(s) are not previously chosen, the user can eliminate more number(s) on the board. Otherwise the game is over.

        Thank you Marc.

         
      • Cedric T Jemison

        Marc,

        I did a little tweeting with this program to help me further the run program:

        10 RANDOMIZE:NC=9:RC=0:DIM B(NC):FOR I=1 TO NC:B(I)=-1:NEXT
        20 R=0:FOR I=1 TO NC:R=R OR B(I):NEXT:IF NOT R THEN GOTO 130
        30 PRINT"Board":FOR I=1 TO 5:IF B(I) THEN PRINT USING "<#>";I;
        40 NEXT:PRINT
        50 FOR I=6 TO 9:IF B(I) THEN PRINT USING "<#>";I;
        60 NEXT:PRINT:PRINT
        70 RC=RC+1:IF RC=1 THEN NTH$(RC)="st" ELSE IF RC=2 THEN NTH$(RC)="nd" ELSE IF RC=3 THEN NTH$(RC)="rd" ELSE IF RC>3 THEN NTH$(RC)="th"
        80 PRINT"Press <enter> to roll the dice. (";RC;NTH$(RC)". roll)";:INPUT A$
        90 D=INT(NC*RND(1))+1:PRINT"You rolled a";D
        100 IF B(D) THEN B(D)=0:GOTO 20
        110 PRINT"Number";D;"is already off the board."
        120 PRINT"Bad roll. You loose.":END
        130 PRINT"Board is empty. You win.":END</enter>

        Now I'm just trying hold each position of each number without truncating to the left. So it will show each eliminated number as blank:

        Board
        <1><2><3><4><5>
        <6><7><8><9>

        Press <enter> to roll the dice. (1 st .roll)
        You rolled a 3</enter>

        Board
        <1><2><4><5>
        <6><7><8><9>

        My goal is this:
        Board
        <1><2> <4><5>
        <6><7><8><9>

         

        Last edit: Cedric T Jemison 2020-03-31
        • Marc 'BlackJack' Rintsch

          Splitting the board values onto two lines by hard coding the loop variable limits and repeating code isn't so nice. Now you can't change the number of numbers on the board by simply changing the value of NC anymore. One solution would be to insert a new line every 5 printed numbers.

          Printing blanks for removed numbers is easy — you already know ELSE.

          NTH$ doesn't have to be an array, you only need the current string, not those from earlier rolls. But an array can be used to simplify the code here. One that is initialised with "st", "nd", and "th" once at the beginning. Then you only need to determine the index needed for the current roll, which is significantly simpler than nesting IF/ELSE three levels deep. In your code its even one level too far because the last IF RC>3 is not really needed. Assuming RC is never <1 it must be greater than 3 if it isn’t 1, 2, or 3.

          10 RANDOMIZE:NC=9:NTH$(1)="st":NTH$(2)="nd":NTH$(3)="rd":NTH$(4)="th"
          20 RC=0:DIM B(NC):FOR I=1 TO NC:B(I)=-1:NEXT
          30 R=0:FOR I=1 TO NC:R=R OR B(I):NEXT:IF NOT R THEN GOTO 140
          40 PRINT"Board":FOR I=1 TO NC
          50 IF B(I) THEN PRINT USING "<#>";I; ELSE PRINT "   ";
          60 IF I MOD 5 = 0 THEN PRINT
          70 NEXT:PRINT:PRINT
          80 RC=RC+1:IF RC>3 THEN I=4 ELSE I=RC
          90 PRINT"Press <enter> to roll the dice. (";RC;NTH$(I)". roll)";:INPUT A$
          100 D=INT(NC*RND(1))+1:PRINT"You rolled a";D
          110 IF B(D) THEN B(D)=0:GOTO 30
          120 PRINT"Number";D;"is already off the board."
          130 PRINT"Bad roll. You loose.":END
          140 PRINT"Board is empty. You win.":END
          
           
          • Cedric T Jemison

            Marc,
            I like the MOD operator because I can use it as 3 where then will be in 3 by 3 instead of me try to move when B(I)=6 by 3 spaces.
            If MOD 5 = 0 then Print
            <1><2><3><4><5>
            <6><7><8><9>
            Instead of marking 2 lines to balance the bottom 4 numbers with 3 spaces to the right if just figured with 9 numbers I can just make it a 3x3 print:
            If MOD 3 = 0 then Print
            <1><2><3>
            <4><5><6>
            <7><8><9>

            I just don't quite get the R=0 and R=R situation of the program, so I can reprogram my hiroller.bas. I managed to shorted the drawing of dices than I had before in 10 lines. Before, it was from lines 5000 to 7120.


            ooo
            ooo


            | o |
            | o |
            | o |


            It's D1 and D2

            I'm trying to get it side by side instead of top and bottom:


            |ooo| | o |
            | | | o |
            |ooo| | o |


            So that is my progress for right now, then I can so work on the eliminating a single number 1 to 9[n1] or a combination of numbers from 2 to 4 numbers on the board. Like If I roll a 10 with D1 + D2 = R1, then the user can decide the numbers use to add the sum of ten. With 2 numbers (7 and 3, or 8 and 2[n1 and n2]); with 3 numbers (2,3 and 5 or 1,6, and 3[n1, n2, n3]); with 4 numbers (only 1,2,3, and 4[n1, n2, n3, n4]) can be eliminated. I also have to make it fool proof such as selected value is not equal to value rolled or you can't pick a zero or you can't pick the same number twice on user's selection.

            Thanks again,

            Cedric

             
  • Cedric T Jemison

    Hi Marc,

    Here's my progress trying to resurrect High Roller:

    10 RANDOMIZE:NC=9:NTH$(1)="st":NTH$(2)="nd":NTH$(3)="rd":NTH$(4)="th"
    20 RC=0:DR=0:DIM B(12):FOR I=1 TO NC:B(I)=-1:NEXT
    30 R=0:FOR I=1 TO NC:R=R OR B(I):NEXT:IF NOT R THEN GOTO 210
    40 PRINT" Board ":FOR I=1 TO NC
    50 IF B(I) THEN PRINT USING "<#>";I; ELSE PRINT " ";
    60 IF I MOD 3 = 0 THEN PRINT
    70 NEXT:PRINT:PRINT
    80 RC=RC+1:IF RC>3 THEN I=4 ELSE I=RC
    90 PRINT"Press <enter> to roll the dice. (";RC;NTH$(I)". roll)";:INPUT A$
    100 DA=INT(6RND(1))+1:PRINT"With dice one, a";DA
    110 DB=INT(6
    RND(1))+1:PRINT"With dice one, a";DB
    120 D=DA+DB:PRINT"You rolled a";D
    130 IF DA=DB THEN PRINT"A double roll!!!":IF DA=DB THEN DR=DR+1
    140 PRINT B(D); DR;
    150 IF D>9 THEN GOTO 220
    160 IF B(D) THEN B(D)=0:GOTO 30
    170 PRINT"Number";D;"is already off the board.":DR=DR-1
    180 IF DR>-1 THEN PRINT "You have ";DR;"marker insurance left."
    190 IF DR>-1 THEN 30
    200 PRINT"Bad roll. You loose.":END
    210 PRINT"Board is empty. You win.":END
    220 IF D>9 THEN INPUT "How many numbers you want to remove?...";RE
    230 INPUT "1ST NUM TO REMOVE...";N(I)
    240 INPUT "2ND NUM TO REMOVE...";N(I+1)
    250 IF RE=3 OR RE=4 THEN INPUT "3RD NUM TO REMOVE...";N(I+2)
    260 IF RE=4 THEN INPUT "4TH NUM TO REMOVE...";N(I+3)
    270 PRINT N(I);N(I+1);N(I+2);N(I+3)
    280 PRINT" Board ":FOR I=1 TO NC
    290 IF B(I) THEN PRINT USING "<#>";I; ELSE PRINT " ";
    300 IF I MOD 3 = 0 THEN PRINT
    310 NEXT:PRINT:PRINT
    320 GOTO 80 </enter>


    Press <enter> to roll the dice. ( 1 st. roll)?
    With dice one, a 6
    With dice one, a 3
    You rolled a 9
    -1 0 Board
    <1><2><3>
    <4><5><6>
    <7><8> </enter>

    Press <enter> to roll the dice. ( 2 nd. roll)?
    With dice one, a 1
    With dice one, a 6
    You rolled a 7
    -1 0 Board
    <1><2><3>
    <4><5><6>
    <8> </enter>

    Press <enter> to roll the dice. ( 3 rd. roll)?
    With dice one, a 6
    With dice one, a 1
    You rolled a 7
    0 0 Number 7 is already off the board.
    Bad roll. You loose.
    Ok  </enter>


    Ok 
    RUN
    Random number seed (-32768 to 32767)? 7843
    Board
    <1><2><3>
    <4><5><6>
    <7><8><9>

    Press <enter> to roll the dice. ( 1 st. roll)?
    With dice one, a 2
    With dice one, a 6
    You rolled a 8
    -1 0 Board
    <1><2><3>
    <4><5><6>
    <7> <9> </enter>

    Press <enter> to roll the dice. ( 2 nd. roll)?
    With dice one, a 6
    With dice one, a 4
    You rolled a 10
    0 0 How many numbers you want to remove?...? 3
    1ST NUM TO REMOVE...? 3
    2ND NUM TO REMOVE...? 5
    3RD NUM TO REMOVE...? 2
    3 5 2 0
    Board
    <1><2><3>
    <4><5><6>
    <7> <9>
    The problem here that I need remove multiple numbers like the 3,5 and 2 from the board so it would look like this:</enter>

    <1>
    <4> <6>
    <7> <9>

    Or force N(I) to be 1,2,and 3 as align with B(I) as -1,-2, and -3

    Press <enter> to roll the dice. ( 3 rd. roll)?
    With dice one, a 2
    With dice one, a 6
    You rolled a 8
    0 0 Number 8 is already off the board.
    Bad roll. You loose.
    Ok 
    Once this part is fixed than I can work on my pervious reply to you including the drawing of the dice. But for now, when the dices are rolled as 10, 11 or 12, that's when the player can decide which numbers to eliminate from 2 numbers to 4 numbers.</enter>

    Thanks as always,

    Cedric

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.