[comp.sys.ibm.pc] disk paging on IBM PC's

rjj@batcomputer.UUCP (03/23/87)

I am looking for an algorithm (written in 'C') that
would do demand disk paging from within a editor.
A language processor we are working on only has enough
buffer space available to keep 400 lines of text in
memory.  What is needed is a small routine that will
update the total document on disk, page out the last
least used pages from memory and  then read in more of
the text from the disk ( the reason for all this is that
the system will be run in language labs that have minimum
configuration IBM PC's). As far as I can tell, only
a couple of popular word processors can do this so it
might be trickier that it seems.  If anybody can point
me down a golden-paved path I would be very grateful.
	Rich Jaenson
	Landscape Architecture Program
	Cornell University
	Ithaca, NY. 14853
	rjj@mathvax.msi.cornell.edu

madd@bucsb.bu.edu.UUCP (03/31/87)

In article <475@batcomputer.tn.cornell.edu> rjj@batcomputer.tn.cornell.edu (rjj) writes:
>
>I am looking for an algorithm (written in 'C') that
>would do demand disk paging from within a editor.
>A language processor we are working on only has enough
>buffer space available to keep 400 lines of text in
>memory.  What is needed is a small routine that will
>update the total document on disk, page out the last
>least used pages from memory and  then read in more of
>the text from the disk ( the reason for all this is that
>the system will be run in language labs that have minimum
>configuration IBM PC's). As far as I can tell, only
>a couple of popular word processors can do this so it
>might be trickier that it seems.  If anybody can point
>me down a golden-paved path I would be very grateful.
>	Rich Jaenson

This is definitely trickier than it seems.  I am currently working on
an editor that is capable of this, and would like to give you some of
my ideas so that you can have a base to build on.  I'm sorry that I
cannot give you prewritten routines -- I don't have them available.

The simplest method of handling paged memory is to treat all of memory
as paged (whether on or off disk) and only access it through certain
routines, which take paging into consideration.  My wordprocessor used
1K "pages" that were stored in linked lists.  If you came to a section
in the list that had a flag set to indicate that it was paged, you
swap out one page (take your pick -- use any algorithm you want to
figure out which page to swap) and reload the other page.  Reset its
pointers to fit it in the correct place in the list.

The list must be made up of three elements, besides those used by your
program.  You must have a pointer to each page (via your language's
structure pointer convention; C would be something like PAGE *page)
and a boolean value to indicate if the page has been swapped.  You
must indicate where on disk the page has been swapped to, as well, and
I recommend you overlap the memory pointer with the disk pointer.  I
personally used an integer value to determine which record number a
particular page was in.  It is an algorithm problem as to how you
determine where on disk to put your record -- I just scanned the list
and kept track of the lowest open page in the file of pages, as well
as remembering the highest page yet written.

There are other advantages to treating all of memory as "paged".  For
instance, it is simple to treat a couple of pages as the entire
file, thus saving you time when you reorganize.  You only have to
move a few K of bytes instead of a few hundred.

I hope this has been helpful.  If you have more questions, write and
I'll clarify things.  Be sure to include several GOOD return paths
(preferable ARPANET).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
          Jim Frost * The Madd Hacker | UUCP: ..!harvard!bu-cs!bucsb!madd
  H H                                 | ARPA:           madd@bucsb.bu.edu
H-C-C-OH <- heehee          +---------+----------------------------------
  H H                       | "We are strangers in a world we never made"

wheels@mks.UUCP (03/31/87)

In article <888@bucsb.bu.edu.UUCP>, madd@bucsb.bu.edu.UUCP (Jim "Jack" Frost) writes:
> In article <475@batcomputer.tn.cornell.edu> rjj@batcomputer.tn.cornell.edu (rjj) writes:
> >
> >I am looking for an algorithm (written in 'C') that
> >would do demand disk paging from within a editor.
> 
> This is definitely trickier than it seems.  I'm sorry that I
> cannot give you prewritten routines -- I don't have them available.

Look through the magazines for an ad for an editor called RED, by
Howard K. Ream. He sells source. Used to be about $100. RED will page
the editor buffer to disk, and I'm sure you could get some good ideas
from that. If you can't find an ad, let me know -- I bought it a couple of
years ago, and never did use it. I'll sell you a slightly used disk and
manual cheap.
-- 
Gerry Wheeler                  {seismo,decvax,ihnp4}!watmath!mks!wheels
Mortice Kern Systems Inc.