home *** CD-ROM | disk | FTP | other *** search
- {unit _HeapSwp;}
-
- {----------------------------------------------------------------------------}
- { _HEAPSWP }
- { }
- { This unit allows a program that uses all available memory for Heap }
- { to still be able to EXEC a program such as COMMAND.COM and return }
- { to the original program. It does this by saving the Heap to disk }
- { and freeing the Heap memory for the EXEC program. After the program }
- { is terminated, the Heap is retrieved from the disk. }
- { }
- { For example: }
- { if PutHeap('.',0) then }
- { begin }
- { SwapVectors; }
- { exec(GetEnv('COMSPEC'),''); }
- { SwapVectors; }
- { GetHeap; }
- { end }
- { else }
- { (*Error Handling*) }
- { }
- {----------------------------------------------------------------------------}
-
- interface
-
- uses crt,
- dos;
-
- {----------------------------------------------------------------------------}
- { FUNCTION HEAPSIZE : WORD; }
- { Return the size of the complete HEAP in paragraphs. }
- { For the number of bytes multiply by 16. }
- {----------------------------------------------------------------------------}
-
- function HeapSize : word; {Returns size of the Heap in Paragraphs}
-
- {----------------------------------------------------------------------------}
- { FUNCTION PUTHEAP( HeapFilePath : PathStr; }
- { UserID : BYTE): BOOLEAN; }
- { }
- { }
- { This function attempts to create a Heap swap file in the HeapFilePath }
- { directory, save the entire Heap to the file, and then deallocate the }
- { the memory used by the Heap for the program to be executed. }
- { }
- { If all is successful the function returns TRUE }
- { The function will return FALSE if -> }
- { 1 - There is not enough room in the HeapFilePath to store the Heap. }
- { 2 - There was a problem in creating or writing the file. }
- { 3 - There was a problem in DeAllocating the Heap Memory }
- { }
- { HeapFilePath is the PATH ONLY. No file name. For example. }
- { '' = Put it in the Root of the Current Drive. }
- { '.' = Put it in the Current Directory of the Current Drive. }
- { 'D:' = Put it in the Root of the D: Drive. }
- { 'D:.' = Put it in the Current Directory of the D: Drive. }
- { 'D:\TEMP' = Put it in the \TEMP Directory on the D: Drive. }
- { }
- { You should not put a '\' on the end of the HeapFilePath. }
- { }
- { The UserID is for NetWork usage. In order to make sure the Swap file }
- { name is Unique for each User on the network. it is up to the Programmer }
- { to determine a unique ID number for each user. On Novell the Physical }
- { Station Number is a perfect choice. On single user systems just use 0. }
- { }
- { The Swap File created will have a name of the form HEAP3.$5 }
- { The 3 indicates the UserID=3. The 5 is a Process ID to keep track of }
- { Multiple programs using _HEAPSWP at the same time. For example a }
- { program could call another copy of itself and a separate Heap Swap file }
- { would be created for each invocation. }
- { }
- { The Heap Swap file will be marked Read Only to discourage crashing the }
- { program by erasing the Swap file. }
- { }
- {----------------------------------------------------------------------------}
-
- function PutHeap(HeapFilePath : PathStr;
- UserID : byte) : boolean;
-
- {----------------------------------------------------------------------------}
- { PROCEDURE GETHEAP; }
- { }
- { This procedure ReAllocates the memory for the Heap and Loads in the }
- { Heap Swap file and erases the swap file. }
- { }
- { Failure to reallocate the memory or correctly read the Swap file is }
- { Bad News ! The program will halt with an error level 1. }
- { }
- { Be Aware that executing a program that permanently allocates memory }
- { such as a TSR while the heap is swapped is going to Crash. }
- { }
- { Be aware the Exit procedures that use variables on the Heap may not }
- { function properly. }
- { }
- { Also be aware that failure to call GetHeap after a PutHeap or }
- { crashing the system before calling a GetHeap will result in }
- { Orphaned Swap files laying around. Re-running the program will }
- { normally clean them up if the program runs in the same environment. }
- { }
- {----------------------------------------------------------------------------}
-
- procedure GetHeap;
-