home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / HEAPSW.ZIP / _HEAPSWP.INT < prev    next >
Encoding:
Text File  |  1989-01-27  |  7.0 KB  |  105 lines

  1. {unit _HeapSwp;}
  2.  
  3. {----------------------------------------------------------------------------}
  4. { _HEAPSWP                                                                   }
  5. {                                                                            }
  6. {    This unit allows a program that uses all available memory for Heap      }
  7. {    to still be able to EXEC a program such as COMMAND.COM and return       }
  8. {    to the original program. It does this by saving the Heap to disk        }
  9. {    and freeing the Heap memory for the EXEC program. After the program     }
  10. {    is terminated, the Heap is retrieved from the disk.                     }
  11. {                                                                            }
  12. {    For example:                                                            }
  13. {    if PutHeap('.',0) then                                                  }
  14. {      begin                                                                 }
  15. {        SwapVectors;                                                        }
  16. {        exec(GetEnv('COMSPEC'),'');                                         }
  17. {        SwapVectors;                                                        }
  18. {        GetHeap;                                                            }
  19. {      end                                                                   }
  20. {    else                                                                    }
  21. {      (*Error Handling*)                                                    }
  22. {                                                                            }
  23. {----------------------------------------------------------------------------}
  24.  
  25. interface
  26.  
  27. uses crt,
  28.      dos;
  29.  
  30. {----------------------------------------------------------------------------}
  31. { FUNCTION HEAPSIZE : WORD;                                                  }
  32. {    Return the size of the complete HEAP in paragraphs.                     }
  33. {    For the number of bytes multiply by 16.                                 }
  34. {----------------------------------------------------------------------------}
  35.  
  36. function HeapSize : word;  {Returns size of the Heap in Paragraphs}
  37.  
  38. {----------------------------------------------------------------------------}
  39. { FUNCTION PUTHEAP( HeapFilePath : PathStr;                                  }
  40. {                   UserID       : BYTE): BOOLEAN;                           }
  41. {                                                                            }
  42. {                                                                            }
  43. {    This function attempts to create a Heap swap file in the HeapFilePath   }
  44. {    directory, save the entire Heap to the file, and then deallocate the    }
  45. {    the memory used by the Heap for the program to be executed.             }
  46. {                                                                            }
  47. {    If all is successful the function returns TRUE                          }
  48. {    The function will return FALSE if ->                                    }
  49. {       1 - There is not enough room in the HeapFilePath to store the Heap.  }
  50. {       2 - There was a problem in creating or writing the file.             }
  51. {       3 - There was a problem in DeAllocating the Heap Memory              }
  52. {                                                                            }
  53. {    HeapFilePath is the PATH ONLY. No file name. For example.               }
  54. {       ''   = Put it in the Root of the Current Drive.                      }
  55. {       '.'  = Put it in the Current Directory of the Current Drive.         }
  56. {      'D:'  = Put it in the Root of the D: Drive.                           }
  57. {      'D:.' = Put it in the Current Directory of the D: Drive.              }
  58. {  'D:\TEMP' = Put it in the \TEMP Directory on the D: Drive.                }
  59. {                                                                            }
  60. {    You should not put a '\' on the end of the HeapFilePath.                }
  61. {                                                                            }
  62. {    The UserID is for NetWork usage. In order to make sure the Swap file    }
  63. {    name is Unique for each User on the network. it is up to the Programmer }
  64. {    to determine a unique ID number for each user. On Novell the Physical   }
  65. {    Station Number is a perfect choice. On single user systems just use 0.  }
  66. {                                                                            }
  67. {    The Swap File created will have a name of the form HEAP3.$5             }
  68. {    The 3 indicates the UserID=3. The 5 is a Process ID to keep track of    }
  69. {    Multiple programs using _HEAPSWP at the same time. For example a        }
  70. {    program could call another copy of itself and a separate Heap Swap file }
  71. {    would be created for each invocation.                                   }
  72. {                                                                            }
  73. {    The Heap Swap file will be marked Read Only to discourage crashing the  }
  74. {    program by erasing the Swap file.                                       }
  75. {                                                                            }
  76. {----------------------------------------------------------------------------}
  77.  
  78. function PutHeap(HeapFilePath : PathStr;
  79.                  UserID       : byte) : boolean;
  80.  
  81. {----------------------------------------------------------------------------}
  82. { PROCEDURE GETHEAP;                                                         }
  83. {                                                                            }
  84. {    This procedure ReAllocates the memory for the Heap and Loads in the     }
  85. {    Heap Swap file and erases the swap file.                                }
  86. {                                                                            }
  87. {    Failure to reallocate the memory or correctly read the Swap file is     }
  88. {    Bad News ! The program will halt with an error level 1.                 }
  89. {                                                                            }
  90. {    Be Aware that executing a program that permanently allocates memory     }
  91. {    such as a TSR while the heap is swapped is going to Crash.              }
  92. {                                                                            }
  93. {    Be aware the Exit procedures that use variables on the Heap may not     }
  94. {    function properly.                                                      }
  95. {                                                                            }
  96. {    Also be aware that failure to call GetHeap after a PutHeap or           }
  97. {    crashing the system before calling a GetHeap will result in             }
  98. {    Orphaned Swap files laying around. Re-running the program will          }
  99. {    normally clean them up if the program runs in the same environment.     }
  100. {                                                                            }
  101. {----------------------------------------------------------------------------}
  102.  
  103. procedure GetHeap;
  104.  
  105.