[net.micro.cbm] Sequential File Help

gibson@trwrba.UUCP (Gregory S. Gibson) (02/27/86)

 I have a problem when I load a sequential file into an array.  It seems
 to be a C64 bug.  After loading the data from the sequential file into
 an array, the program works find for awhile until suddenly, for no
 apparently reason, the program stops for 10-20 seconds then continues
 as if nothing happened.  After studying this problem, I have discovered
 how to reproduce it. 

   1.  Create a sequential file
   2.  Read the file into an array and print the amount of remaining
       RAM.
       Example:

100    DIMENSION ARRAY$(500)
200    T$="0:FEB 86,S,R"
250    OPEN 15,8,15
300    OPEN 4,8,4, T$
400    FOR I=1 to 200
500    INPUT#4,ARRAY$(I)
600    IF ST>0 THEN 800
700    NEXT I
800    X=TI:PRINT" READ COMPLETE":PRINT" AVALILABLE RAM IS"
900    PRINT FRE(O) - (SGN(FRE(O)) < 0)*65535 :REM  THIS IS THE DELAY
910    Y=(TI-X)/60: PRINT" TIME DELAY=";Y
920    PRINT" STOP PROGRAM"
930    CLOSE4: CLOSE15
940    STOP
950    END
	
 The larger the loop, the longer the execution delay.  It seems the BASIC
 array or memory pointers get confusioned.

 Thanks in advance

Gregory Gibson
{decvax,ucbvax,ihnp4}!trwrb!trwrba!gibson

joels@tekred.UUCP (Joel Swank) (03/06/86)

> 
>  I have a problem when I load a sequential file into an array.  It seems
>  to be a C64 bug.  After loading the data from the sequential file into
>  an array, the program works find for awhile until suddenly, for no
>  apparently reason, the program stops for 10-20 seconds then continues
>  as if nothing happened.

Sorry, this is not a bug, but a feature. You got the old 'Garbage Collection'
wait.  This happens whenever string space is used up, or whenever a FRE
function is used. BASIC uses up string space from the top of memory down.
New strings are allocated out of unused space. When a string is reassigned
its old data is just left unused, and new space is allocated. To re-use
the old space the string space is compressed leaving only the currently
valid strings. It also has to compress to find out how much memory is
free. This can be quite anoying. When memory is really full, I have seen
compression take 5 minutes, followed by a few seconds of processing,
followed by another 5 minute wait, etc. The problem is worse when lots
of strings are in use at once (such as string arrays). The problem can
be minimized by using as few strings as possible. If it's any consolation, 
the new improved BASIC in the C-128 has an efficient way of handling this.

Joel Swank
Tektronix, Redmond, Oregon

brown@nicmad.UUCP (03/20/86)

In article <1868@trwrba.UUCP> gibson@trwrba.UUCP (Gregory S. Gibson) writes:
>
> I have a problem when I load a sequential file into an array.  It seems
> to be a C64 bug.  After loading the data from the sequential file into
> an array, the program works find for awhile until suddenly, for no
> apparently reason, the program stops for 10-20 seconds then continues
> as if nothing happened.

You have been hit with the common STRING GARBAGE COLLECTION syndrome.

When C64 Basic needs more string space and it finds that there is space left,
but a little unorganized, it collects the good data and puts the open
space at the end, so that it can be used (something like that).  But the
net result is that you have to wait while it does that.

So, don't worry, you have to live with it.
-- 

              ihnp4------\
            harvard-\     \
Mr. Video      seismo!uwvax!nicmad!brown
              topaz-/     /
             decvax------/