Dec 212017
 
Run large programs from within Clipper.
File SWAPDEMO.ZIP from The Programmer’s Corner in
Category Dbase Source Code
Run large programs from within Clipper.
File Name File Size Zip Size Zip Type
SWAP.OBJ 4323 2453 deflated
SWAPDEMO.DOC 7674 3020 deflated
SWAPDEMO.PRG 2486 1137 deflated
SWAPSTRT.PRG 275 177 deflated

Download File SWAPDEMO.ZIP Here

Contents of the SWAPDEMO.DOC file





Swap! - Copyright (C) 1988, Gregory A. Martin
-------------------------------------------------------------------

SWAP! requires Clipper Summer '87.

To compile and link the SWAP! demo type in the following:

clipper SwapStrt -m
clipper SwapDemo
plink86 fi SwapStrt,SWAP,SwapDemo lib \clipper\clipper,\clipper\extend out SwapDemo

Of course, the library path \clipper\ should be replaced with wherever
your Clipper and Extend libraries are located.

Follow this same general course to link this SWAP! (demo) .OBJ with any
of your own large Clipper applications.



Swap! lets a large Clipper application load and run another program
whose memory requirements are larger than can be satisfied by the
SET CLIPPER= / RUN (or !) combination.



How It Works
------------

Imagine what memory looks like when a Clipper application is
running (this is a simplified picture, of course):

high memory
+-------------+ --+
| | |
| | |
| Free Memory | +-- Normally, only this memory is available to
+-------------+ | Clipper to RUN/! programs
| Clipper's | |
| Buffers | |
+-------------+ --+
| | Swap! works by saving the memory used by
| | the Clipper program itself to disk, freeing
| | this memory, loading the program to be run
| | into the memory previously used by the
| | Clipper program, then restoring the Clipper
| Clipper | program from disk when the second program
| Application | terminates.
+-------------+
| |
| DOS |
+-------------+
low memory

Here's what memory looks like just before Swap! calls another
program:

high memory
+-------------+ --+
| | |
| | |
| | +-- Now up to THIS MUCH memory is available to
| | | run programs!
| | |
| | |
| | |
| | | Pretty amazing, huh?
| | |
| | | Despite what you may think, saving the
| | | memory to disk takes very little time, since
| Free Memory | | hard disk data transfer rates are typically
+-------------+ --+ 100K to 800K per second. Saving 640K on a
| Swap! | 16 MHz 386 computer with a standard hard
+-------------+ disk controller takes only about 6 seconds.
| | Usually, far less memory needs to be saved.
| DOS |
+-------------+
low memory



Using Swap!
-----------

The syntax for calling Swap! is:

[return = ] Swap( , )

where [return =] is an optional variable to store the return
value (see below)

is the number of K bytes to free

is any valid DOS command line.


Possible return values are:
0 - no error
3 - not running DOS 3.0 or above
4 - invalid parameters
5 - cannot find COMSPEC= in the environment
6 - encountered invalid memory control blocks
7 - not able to create temporary file
8 - error saving memory to disk
9 - error deallocating memory (may leave the Clipper
program with less memory than it had before and
may lead to misc. errors)
10 - critical error in reallocating memory (may
not be recoverable)
11 - critical error in restoring memory from disk
(may not be recoverable)

is the amount of memory, in K, that is required by the
program to be run. If 0 is specified, as much memory as
possible is freed.

may be any valid DOS command line. This is
what would normally be after the RUN (or !) in a Clipper
program. If a null string is specified, a COMMAND.COM shell
will be initiated, which can then be EXITed to return to the
Clipper application.

Note that Swap! requires the availability of one file handle
to create the temporary disk file. If no handles are available,
Swap! returns with an error code of 6.

Also, Swap! must be able to locate the command processor
(COMMAND.COM or its equivalent) through the COMSPEC environment
variable. If COMSPEC= cannot be found in the environment,
Swap! returns with an error code of 4.



LINKing with SWAP.OBJ
---------------------

When SWAP! frees memory it starts at high memory (which may be
unused) and travels down to low memory freeing up as much memory
as needed, up to the location of the SWAP.OBJ in memory. Therefore
if you have created a huge Clipper application SWAP! should be
placed as close to the beginning of the list used in linking as is
possible. SWAP! should not be placed in an overlay, but at the
beginning of your main .EXE.

For best results, create and compile a small .PRG that contains
only one line: DO

Then LINK (PLINK86, TLINK, etc.) the small .OBJ, SWAP.OBJ, and
your program's .OBJ. For example, if the small .PRG is called
START.PRG, and your program's .OBJ is MYPROG, link like this:

LINK START + SWAP + MYPROG,,,\CLIPPER\CLIPPER
or
PLINK86 fi START,SWAP,MYPROG

This places Swap! as near the start of memory as possible (about
50 bytes, or so).

With this arrangement Swap! can free up all but about 10K!

Here's an example of what Swap! can do:

Memory currently available: 656624
from the DOS prompt on a 386 running PC-MOS/386.

Swap(0, "") from within a large Clipper application.

Memory currently available: 645872
from the shelled DOS prompt. Swap! used only 10,752 bytes!

Swap! uses even less memory under MS-DOS. Understand that this
10K or so is only not available to the secondary, or RUN,
program. It is NOT taken out of system memory the way a
terminate-and-stay-resident program takes memory (Swap! is not
a TSR).

Incidently, Swap! can be called "recursively" by programs with
no ill effects: A program can Swap! to a secondary program,
which can Swap! to a ternary program, and so on. Each
instantiation only detracts another 10K or so from available
memory.

Again, pretty amazing, huh?



Credits and Information
-----------------------

Swap! was written by Greg Martin with technical and moral
support from J. David Reynolds.

Swap! requires DOS 3.0 or greater (or something equivalent)
in order to create temporary files, and the Clipper Summer '87
compiler.

Swap! has been tested under MS-DOS 3.1, 3.2, and 3.3;
PC-MOS/386; and Novell Netware 2.0.

HOWEVER:

What Swap! does is very, very tricky and OS dependent. DOS
was definitely never meant to be able to Swap! programs this
way.

THEREFORE:

We make no representations or warranties with respect to the
merchantability or fitness of this program for any particular
purpose. In no event shall Gregory A. Martin be liable for any
loss of profit or any commercial damage, including but not
limited to special, incidental, consequential or other damages.
Further, we reserve the right to revise this program and

documentation at any time without obligation to notify any
person or organization of such revision.


To order a non-demo version of SWAP!, send $35.00 check of money
order to:

Greg Martin
PO Box 77
DuQuoin, IL. 62832



Misc.
-----

Clipper is a trademark of Nantucket Corp.
MS-DOS is a trademark of MicroSoft, Inc.
PC-MOS/386 is a trademark of The Software Link
Novell Netware is a trademark of Novell, Inc.


 December 21, 2017  Add comments

Leave a Reply