Announcement

Collapse
No announcement yet.

Out of string space (Error 7) - What conserves most s-space when using arrays(DIM)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Out of string space (Error 7) - What conserves most s-space when using arrays(DIM)


    Hi All ! !

    Ti’s only me again . . .

    Firstly, I really write bloated code (*kick me hard*), every time a client wants a new feature I just add a sub routine . . .

    Now I sit with programs that are like 460kb big . . I need to like know how can I get more string space (not get error 7 once to often) when I run such a large program.

    Example of my array dimensions :-

    Code:
    ‘ In the code I check how much memory is left –set para$() and dimension NUM and FLD accordingly)
    
    IF VAL(PARA$(160))>0 THEN
       NUM = VAL( PARA$(160) )
       FLD=VAL(PARA$(161)
       ELSE
       Num = 200
       FLD=49
    END IF
    
    DIM Y1$(NUM),Y2$(NUM),Y3$(NUM),Y4(NUM), Y5(NUM), Y6(NUM), Y7(NUM), Y8(NUM), Y9$(NUM), Y9(NUM), Y10$(NUM), Y11$(NUM), Y14(NUM), Y15$(NUM),BO_Y11$(NUM)
    
      DIM FLD%(FLD), FLD$(FLD), IFLD$(FLD), DD$(FLD), D$(FLD), PS$(30), IPS(30)
      DIM PD$(60), NSR(60), PA(60),SR$(60)
      DIM M$(5), L$(10),BOS(20)
      DIM B$(20), C(20)
      DIM BC(NUM), C$(15)
      DIM A%(100), B%(100)
      DIM ACC$(200)
    What I need to know is :-

    1) Does my usage of NUM (In source) really make any difference
    2) Does DIM A$(100) take up more space than dim a$$(100): map a$$() * 30
    3) How does static and dynamic arrays contribute to memory overhead.
    4) What can you use to flush memory to recover space does fre() help?
    5) Where can I find a good tutorial that will explain memory overhead ?

    Now that’s a lot`ta questions . . .

    Any takers . . .

    JustBASit www.compubyte.co.za


    ------------------
    BASit
    www.witelafrica.net
    [B][email protected]
    JustBASit

    -------------------
    www.compubyte.co.za
    ------------------- [email protected]

  • #2
    Well, an honest programmer. Actually admitting you write bloat
    ware. I can't help but admire someone like that.

    Anyway, on to your question:
    The more code you write > the bigger the .EXE > the less amount
    of string space you have available.

    Have you checked out the CHAIN/RUN options PB/DOS has available?
    If you can chop up your program into smaller segments, the more
    memory you will have available for strings and data.

    Some time ago, Tom added a wish item from me: The ability to
    store string data into EMS/XMS memory, but I haven't heard from
    him about this. Probably won't since PB's policy prohibits it.


    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      Away from PB/DOS for a while, so I may miss something, but..
      1) Does my usage of NUM (In source) really make any difference
      Not for purposes of memory usage, except that the dynamic array may be ERASE'd.
      2) Does DIM A$(100) take up more space than dim a$$(100): map a$$() * 30
      I think it actually takes less memory, until such time as you actually assign values to the elements of A$(). I believe flex strings allocate their size immediately (I could be wrong on this one real easy); dynamic string arrays allocate memory as needed based on the current $STRING settting and the number of characters currently stored in each element of the array.
      3) How does static and dynamic arrays contribute to memory overhead.
      The same, except that you can't ERASE and free the memory of static arrays. If an array is static, it takes up the space from start to finish. As a rule, I always used dynamic arrays in all my MS-DOS programs.
      4) What can you use to flush memory to recover space does fre() help?
      In terms of a silver bullet which will reduce the current memory usage all you can do is ERASE arrays you don't need any more. FRE("") may help, but that's just a Band-Aid(r) when surgery (re-design) is the indicated therapy.

      In terms of design, you can use more LOCAL arrays (which automatically erase themseleves when you exit a procedure), and in general cut down on the use of GLOBAL and STATIC variables.

      Probably the best bang-for-the-buck-memory-saver: instead of using arrays to store variables, store those data in a disk file and read the values as you need them.

      5) Where can I find a good tutorial that will explain memory overhead
      Never seen one; further, good 'memory management' tends to be application specific.

      Mr. Bishop's suggestion to go to a CHAIN design will help, but savings you gain there will be limited to 'code space' savings if you use a lot of COMMON data. From the limited info you posted, it appears memory usage by data is more a problem for you.


      MCM
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Hi people !

        Ta ! Thanks ...

        Michael, after reading your suggestions, I decided to erase the arrays after they completed their purpose and redim as and when needed . . works wel . .

        I still have to ensure that my memory never goes below the required value, so I use fre(-1) before deciding to dim an array . .

        As for writing to disk, *hehe* I do that all the time . . I need speed and speed comes at a price . .

        bye now . . have a great weekend . .

        JustBASit www.compubyte.co.za




        ------------------
        BASit
        www.witelafrica.net
        [B][email protected]
        JustBASit

        -------------------
        www.compubyte.co.za
        ------------------- [email protected]

        Comment


        • #5
          Basit,
          You didn't say, but have you set the $STRING directive to 1, or are you using the default setting of 32. If you are using a lot of smaller strings, the lower number will help a lot.
          regards, Ian

          ------------------
          [email protected]
          :) IRC :)

          Comment


          • #6
            Hi Ian,
            Originally posted by Ian Cairns:
            ...have you set the $STRING directive to 1, or are you using the default setting of 32..
            For normal non-array strings (Eg. A$) I dont bother to to set any length . . .
            Does it make a difference if I set a length for each variable(non-array) that I use?
            when it comes to numeric variables I just use DEFSNG A-Z . .

            Yeh ~ bloated code . . .so now I wan`na conserve some memory . .
            using fre(-1) and doing a check frequently in the code helps right now to ensure no error 7 occurs . .

            But it sure ain`t good programming :-)

            Ta ! Thanks . .

            JustBASit
            www.compubyte.co.za
            [email protected]


            [This message has been edited by Basit Bulbulia (edited November 08, 2003).]
            JustBASit

            -------------------
            www.compubyte.co.za
            ------------------- [email protected]

            Comment

            Working...
            X