Jump to content

Photo

STACK, DATA, and strings


46 replies to this topic

#1 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 11:38 AM

Bear with me... I'm going to work through an issue in my head here and I hope someone might have some additional opinions that might give me a little better understanding.  Thanks in advance.

 

I'm working on a project right now that requires a significant amount of text to be available to the program for display.  I have chosen to put all the text into DATA statements, and then use a small subroutine to load all the text into a string array.

 

It works beautifully, but I am noticing that it is chewing through my stack space.  So far I have 33% of all the required text in DATA statements, but my stack space has been cut in half with just the 1/3 of text I need.  I still have enough PROGRAM space, I think, to finish the project.

 

Two things: 

 

1) I don't mind hitting a disk for the data, but I only want to do it once.  This means that the stack space will still have to absorb all this text into the string arrays, and we will probably run out of stack space. 

 

 

Example of #1: (text on disk pulled into a string array)

Initialize
Open disk file
Read all text from disk and feed it into a text array
Close disk file
 
Begin Program
Display Text from string arrays
End Program
 

In this scenario we save PROGAM space, but not STACK space.

 

 

2) I COULD read the text directly from the DATA statements and bypass the use of string arrays.  This, however, would require that all the DATA is in my program at all times, and would significantly cut down on my PROGRAM space.

 

Example of #2: (text read from DATA statements and displayed as needed)

Initialize
 
Begin Program
Display text from DATA statements as needed using RESTORE
End Program
 

In this scenario, we save STACK space, but not program space

 

 

Perhaps there is something I missed here... Any thoughts?


Edited by Opry99er, Mon Jan 8, 2018 11:49 AM.


#2 adamantyr OFFLINE  

adamantyr

    Stargunner

  • 1,338 posts

Posted Mon Jan 8, 2018 11:49 AM

You're actually doubling your usage with that approach.

 

If you want to be as efficient as possible, you either:

  1. Store your text in DATA statements and READ them into a single static string only as needed. This requires copious use of RESTORE commands to point to the right location to read text from
  2. Store all your text on disk and read them into string arrays at the start of the program

If you are already seeing half the stack burned with only 1/3 of your actual data complete, that means you may not have enough space for it using a single method. You could use both methods though to share the load between the two memory types.



#3 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 11:49 AM

Sorry, the formatting got screwy and it dropped half my post off.  I sort of fixed it now



#4 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 11:57 AM

You're actually doubling your usage with that approach.

 

If you want to be as efficient as possible, you either:

  1. Store your text in DATA statements and READ them into a single static string only as needed. This requires copious use of RESTORE commands to point to the right location to read text from
  2. Store all your text on disk and read them into string arrays at the start of the program

If you are already seeing half the stack burned with only 1/3 of your actual data complete, that means you may not have enough space for it using a single method. You could use both methods though to share the load between the two memory types.

 

 

I think I can absorb more of a hit to my PROGRAM space at this point than STACK.  I may need to re-think the extent of detail in the text.



#5 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 5:12 PM

One nice feature of my DATA is the padding. Each segment of data takes up 9 DATA statements. I need only offset the RESTORE by that many statements in order to retrieve the correct information.

The question is, can I GOTO A... where A is a variable containing a line number. I havent tested it yet, but Im sure we could find a way to skin that cat. :)

#6 Willsy OFFLINE  

Willsy

    River Patroller

  • 3,062 posts
  • Location:Uzbekistan (no, really!)

Posted Mon Jan 8, 2018 6:43 PM

You don't need to place your strings in arrays, they're already in memory as data statements. Why have them in memory twice? ;-)



#7 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 6:50 PM

Perhaps someone with access to a terminal could try it out for me? :D


10 CALL CLEAR
20 A=100
30 GOTO A
40 ON ERROR PRINT FAIL
50 END
100 PRINT SUCCESS
110 END

Edited by Opry99er, Mon Jan 8, 2018 6:52 PM.


#8 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 6:52 PM

You don't need to place your strings in arrays, they're already in memory as data statements. Why have them in memory twice? ;-)



Yes sir... I have two options... put them in arrays (drawn from disk) or use DATA statements to house the data. Im trying to find the best way to accomplish the goal.

#9 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 6:53 PM

10 CALL CLEAR
20 A=100
30 GOTO A
40 ON ERROR PRINT FAIL
50 END
100 PRINT SUCCESS
110 END



It keeps taking the quotations out of my PRINT statements for some reason...

#10 adamantyr OFFLINE  

adamantyr

    Stargunner

  • 1,338 posts

Posted Mon Jan 8, 2018 6:58 PM

You can't GOTO or GOSUB based on variables.

Use an ON GOTO command with a list of RESTORE statements.

#11 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 7:02 PM

Wow.. that method will eat up a ton of space with 36 data sets. :o

But it probably (sadly) is the most efficient way. Appreciate the tip. :)

Edited by Opry99er, Mon Jan 8, 2018 7:03 PM.


#12 InsaneMultitasker OFFLINE  

InsaneMultitasker

    River Patroller

  • 2,122 posts

Posted Mon Jan 8, 2018 7:42 PM

If you can take the hit to the stack, loading the data from disk is a good option. 



#13 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 8:28 PM

Thats what I am hoping to do... but I dont think the stack will be able to withstand the onslaught of data.

Im going to try though. Adams suggestion will likely be my only option, but Im going to try to load the text data in one big WHAM from disk and cross my fingers.

Edited by Opry99er, Mon Jan 8, 2018 8:29 PM.


#14 TheBF OFFLINE  

TheBF

    Dragonstomper

  • 616 posts
  • Location:The Great White North

Posted Mon Jan 8, 2018 9:10 PM

Thats what I am hoping to do... but I dont think the stack will be able to withstand the onslaught of data.

Im going to try though. Adams suggestion will likely be my only option, but Im going to try to load the text data in one big WHAM from disk and cross my fingers.

 

 

It's been 30 something years but I know I built a pretty big application on TI-BASIC that used a database of information and I could read the records from disk with just an record number.

(it even used a binary search for find key strings in the records. :-)   You should have heard the old disk drives chunking!)

 

Couldn't you make a separate program that creates all your text on a file and then the final program can pull them in by record number, like you would in an array, and print them to the screen?

That way you only have the strings in memory that you need to display at the time.

 

Am I missing something else important?



#15 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Mon Jan 8, 2018 10:57 PM

No... only that if I pull data from an external source, I can only do it once.

This program is being designed to run from tape, so record access is tough and limited. I want to load the program into memory, then hit a big record pull from cassette all at once to populate the arrays...

Or, as has been suggested, keep all records in DATA statements and access them as needed using RESTORE.

#16 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Tue Jan 9, 2018 1:01 AM

Had some success!  I was able to put all the data into a data file and pull it all in one clean shot.  It leaves me with only 2K of stack space left, but I think that is okay.

 

I need to learn the size limits of data files that can be pulled from CS1, because my current data file is a hair over 9K.  The main program is now less than 2K, but that will grow significantly now that I have some headroom.

 

Thanks for the suggestions, folks.  :)



#17 TheBF OFFLINE  

TheBF

    Dragonstomper

  • 616 posts
  • Location:The Great White North

Posted Tue Jan 9, 2018 7:21 AM

No... only that if I pull data from an external source, I can only do it once.

This program is being designed to run from tape, so record access is tough and limited. I want to load the program into memory, then hit a big record pull from cassette all at once to populate the arrays...

Or, as has been suggested, keep all records in DATA statements and access them as needed using RESTORE.

 

 

AH... I missed the Cassette component. Serial access only.



#18 Willsy OFFLINE  

Willsy

    River Patroller

  • 3,062 posts
  • Location:Uzbekistan (no, really!)

Posted Tue Jan 9, 2018 3:11 PM

It's time to buy Buck a PEB, papa! 😀

#19 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Tue Jan 9, 2018 5:20 PM

Lol!!! Weve got PEBs... This is primarily a Because its There deal. There will be no official or unofficial release for diskette. If this thing comes together as planned, youll either need a modem or a cassette player to play it. :D

Edited by Opry99er, Tue Jan 9, 2018 5:20 PM.


#20 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Tue Jan 9, 2018 5:21 PM

Why is Atariage erasing all my quotation marks around words or phrases? Hmmm....

#21 senior_falcon OFFLINE  

senior_falcon

    Stargunner

  • 1,177 posts
  • Location:Lansing, NY, USA

Posted Tue Jan 9, 2018 6:38 PM

Why is Atariage erasing all my quotation marks around words or phrases? Hmmm....

Hi Opry:

"You can have all the quotes you want.  Click on the <> icon and you can paste in code or,
for that matter type it in as I am doing now."
10 PRINT "HELLO WORLD"

Edited by senior_falcon, Tue Jan 9, 2018 6:38 PM.


#22 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Tue Jan 9, 2018 7:00 PM

Test

#23 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Tue Jan 9, 2018 7:01 PM

Hmm.... it appears my mobile version doesnt play nicely...


Test with code tags... Test



#24 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 9,789 posts
  • Location:Hustisford, WI

Posted Tue Jan 9, 2018 7:01 PM

Even inside the code tags it isnt working. Might need to switch to desktop version to figure it out

#25 sometimes99er OFFLINE  

sometimes99er

    River Patroller

  • 4,113 posts

Posted Wed Jan 10, 2018 12:48 AM

Test your www.Opry99er.com too. ;)






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users