Newsgroups: comp.editors
Path: utzoo!utgpu!watserv1!watmath!mks.com!ant
From: ant@mks.com (Anthony Howe)
Subject: Re: REPOST: editor.101
Date: Thu, 13 Jun 91 15:05:53 GMT
Message-ID: <1991Jun13.150553.14445@mks.com>
Organization: Mortice Kern Systems, Waterloo, Ontario, CANADA
References: <1991Jun11.195732.25500@wpi.WPI.EDU> <1991Jun12.143930.14186@mks.com> <1991Jun12.202509.14825@wpi.WPI.EDU>

rcarter@wpi.WPI.EDU (Randolph Carter (nee. Joseph H. Allen)) writes:
>With the scratch file technique, do you combine the files together when you
>reach some maximum?  Or am I misunderstanding it...

Roughly the scratch file technique is somewhat similar to the
description of Elvis' buffering technique.

---longish summary----

I have a file, a paging area, and a scratch/page file.  I read the
file in line by line, building a line table of seek pointers for each
paged line.  So there are two layers the line table (liner) which sits
on top of a pager.

Every time I wish to view a line (redraw the screen) I would call the
line table primitives to lookup the seek pointer, which in turn would
see if that seek pointer is in memory or fetch it from the page file,
passing up the memory pointer of the null terminated string/line.

To delete a line, shuffle down the line table of seek pointers to
delete it.  To insert a line, shuffle up the table to make room for
the seek pointer entry returned from the pager.  To change a line just
replace the old seek pointer with the new seek pointer.

Every request to page out a portion of memory will just append the
block to the end of the page file/memory structure.  So the current
edit line would be read into page memory, copied to an editor buffer,
modified, then  paged out.  All this would be layered: editor->
liner-> pager.

The scratch file technique (described in "Software Tools" by K&P,
chapter 6) is implemented via the pager.  In my implementation the
pager has been embellished with memory caches for the pages, which I
picked up from a CS course a couple of years ago.

(See I told you it was similar to the Elvis buffer description).

Now, the advantages of this.

1) Undo is implemented by remembering the current line table of seek
pointers before updating/inserting/deleting a line.  Also multiple
levels of undo could be maintained since the page file should have
every change since the start of the session.

2) It should be possible to edit files larger than memory (which on
computers with less than a mega of RAM is an advantage) giving limited
virtual memory.  Also if the pager and liner modules are careful, the
editor could edit either binary or text.

3) And the advantage I really like is I can use the seek pointers as
unique line identifiers for use in a screen update algorithum similar
to the one described in Miller's book "A Software Tools Sampler".

4) With a bit more smarts, the line table of seek pointers could also
be paged providing the final element of virtual memory.

5) If your page memory is large enough then most edit sessions can be
kept entirely in memory for fast access (since most source modules should
be reasonable chunks (<30k is reasonable, 50k is gross, 100k is crazy)).  
Memory shuffling would be limited in most cases (I would hope).

Of course there may be a physical limitation on the seek pointers,
which would mean the line table doing garbadge collection on the page
file (not at all for most reasonable edit tasks; unreasonable might be
editing 900k a dictionary for a 5 hour session).  If the line table
and pager are gerneral enough, you create another page file, read in
the current lines from the current page file, page then out to the new
file and update the line tabel with the new seek pointer into the new
file, lastly dispose of the now obsoleted page file.

The EDITOR.201 (Virtual Memory Technique) article I plan for this summer 
should provide a bit more detail and code fragments.  

- ant

-- 
ant@mks.com                                                   Anthony C Howe 
Mortice Kern Systems Inc. 35 King St. N., Waterloo, Ontario, Canada, N2J 6W9
"Fate favors fools, small children, and ships named Enterprise" - Riker
