Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!hp4nl!and!berto From: berto@and.nl (Bert van Oortmarssen) Newsgroups: comp.lang.pascal Subject: Re: SHRINK BEFORE RUNNING A CHILD PROCESS Message-ID: <913@baby.and.nl> Date: 14 Jun 91 09:46:13 GMT References: <11940@j.cc.purdue.edu> Organization: AND Software BV Rotterdam Lines: 73 In article <11940@j.cc.purdue.edu> zhou@brazil.psych.purdue.edu (Albert Q.Zhou) writes: >In Turbo Pascal, the dynamic memory to be used in a program has to be >specified during the compilation by $M. However, when you run a child >program with exec, you can not use any part of the memory already >allocated for the heap even if it is free. Is it a way to get around this? > Try this .... Bert van Oortmarssen unit ushell; (***************************************************************************** *** EXEC *** *** Now you can allways use the {$M xxxxx,xxxxx,655360 } compile options *** *** works with TP4.0 & 5.0, other versions not tested. *** *** see chapter "Inside Turbo Details" of your manual *** *****************************************************************************) interface uses crt,dos; PROCEDURE SHELL (path, CmdLine : string; minimumavail : longint); implementation PROCEDURE SHELL (path, CmdLine : string; minimumavail : longint); var regs : registers; FreelistSize, PargrInUse : word; SaveFreelist : pointer; begin if (maxavail } else begin { be careful with word-arithmetic ! } FreelistSize := $FFFF- (Ofs(FreePtr^)-1); { save the Freelist, allocate room for it } GetMem(SaveFreelist, FreelistSize); { Copy the Freelist ... } Move (FreePtr^, SaveFreelist^, FreelistSize); end; { how many paragraphs are in use ?? } PargrInUse := Seg(HeapPtr^) - PreFixSeg; regs.AH := $4A; { see any good DOS-book ... } regs.ES := PreFixSeg; regs.BX := PargrInUse+2; { one pargr. spare } MsDos(regs); { shrink !!!!!!!!!!!!!! } Exec(path, CmdLine); { do what you want to do ... } { add code that checks doserror variable } regs.AH := $4A; { reclaim memory } regs.ES := PreFixSeg; regs.BX := Seg(FreePtr^) + $1000 - PreFixSeg; { $1000 because of the word arithmetic, $1000 pargr. } { is 65536 bytes } MsDos(regs); { expand !!!!!!!!!!!!!! } { Restore the Freelist and destroy the copy of it } if FreelistSize>0 then begin Move (SaveFreeList^, FreePtr^, FreelistSize); FreeMem(SaveFreelist, FreelistSize); end; end; BEGIN END.