{"id":112825,"date":"2026-11-03T07:00:00","date_gmt":"2026-11-03T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=112825"},"modified":"2026-11-03T07:55:06","modified_gmt":"2026-11-03T15:55:06","slug":"20261103-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20261103-00\/?p=112825\/","title":{"rendered":"How do you implement a random-access database when you don&#8217;t have random-access external storage?"},"content":{"rendered":"<p><a title=\"10 REM&quot;_(C2SLFF4\" href=\"https:\/\/beej.us\/blog\/data\/mystery-comment\/\"> The mystery comment<\/a> investigated by <a href=\"https:\/\/beej.us\/blog\/\"> Beej&#8217;s Bit Bucket<\/a> reminded me of a similar trick in an Apple ][ telephone directory program.<\/p>\n<p>The base Apple ][ was sold without a floppy drive. The only supported external storage device in the base unit was a cassette I\/O port. Yet there was a database program for digitizing your phone list.\u00b9 How did it do database stuff when the only I\/O was a cassette drive? It could not programmatically start or stop the tape, or programmatically rewind or advance it.<\/p>\n<p>If you took a listing of the program (which was written in BASIC), it began with a comment block saying not to edit any lines before line 1000. And then you saw your own telephone directory stored in <code>DATA<\/code> statements.\u00b2 Followed by a bunch of dummy <code>DATA<\/code> statements. And then the program began.<\/p>\n<p>Wait, how did your telephone directory show up as <code>DATA<\/code> statements? The BASIC <code>DATA<\/code> statement was a place for the program developer to store tables of precalculated read-only data, to be consumed by the <code>READ<\/code> statement at runtime. They shipped the program to you without your telephone directory in it, and yet somehow your telephone data ended up in the program.<\/p>\n<p>That&#8217;s because the program used its own <code>DATA<\/code> statements as the memory for a database.<\/p>\n<p>When it wanted to read from the database, it read the data via the usual <code>READ<\/code> command. And when it wanted to write to the database, it used self-modifying code to <code>POKE<\/code> the information back into its own <code>DATA<\/code> statements.<\/p>\n<p>When you told the program that you wanted to save your changes, it told you to turn on the cassette player, and then it invoked the <code>SAVE<\/code> command to save the program to cassette. And since the program modified itself to contain your telephone data, saving the program also saved your data that was embedded inside it.<\/p>\n<p>When you wanted to use your telephone directory, you loaded the program from cassette and ran it.<\/p>\n<p>Now, the Apple ][ did have routines in the monitor ROM to save a block of memory to cassette, so it could have saved the database to tape in a more traditional manner. But that would have meant that when you wanted to use your telephone directory, you first had to load the program from cassette and run it, and then you had to set up the cassette a second time to load the database. Saving the entire program meant that the two load operations (loading the program and loading the data) were combined into a single cassette pass.<\/p>\n<p>\u00b9 This was back in the early days when the sales pitch for personal computers included &#8220;Organize your recipes!&#8221; and &#8220;Digitize your telephone directory!&#8221; Things that nobody ever actually did. (I don&#8217;t know how many people used it for personal finance, but it was definitely <a title=\"VisiCalc: Information from its creators, Dan Bricklin and Bob Frankston\" href=\"http:\/\/www.bricklin.com\/visicalc.htm\"> very popular for <i>business<\/i> finance<\/a>.)<\/p>\n<p>\u00b2 At least, I think it was <code>DATA<\/code> statements. Maybe it was comments. But the same principle applies.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You just store it all in memory, in your own program.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-112825","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>You just store it all in memory, in your own program.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=112825"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112825\/revisions"}],"predecessor-version":[{"id":112826,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112825\/revisions\/112826"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=112825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=112825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=112825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}