Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!wuarchive!decwrl!shelby!portia!dhinds From: dhinds@portia.Stanford.EDU (David Hinds) Newsgroups: comp.lang.pascal Subject: Re: TP Dynamic variable disposal Summary: Pascal's "Heap" isn't the same as Dos's "Heap" Message-ID: <6957@portia.Stanford.EDU> Date: 22 Nov 89 23:25:10 GMT References: <21510@adm.BRL.MIL> <4620@ncsuvx.ncsu.edu> Sender: David Hinds Organization: Stanford University Lines: 32 In article <4620@ncsuvx.ncsu.edu>, unkydave@shumv1.uucp (David Bank) writes: > Anyway, as I understand dynamic memory allocation on the PC, > requests for memory are made to DOS. DOS returns a pointer to the > allocated memory or nothing if there was a problem (like no more > available memory) > > Inside your TP program, you can return allocated memory to the > heap using the Dispose() standard function. This frees memory as far > as both the program and DOS are concerned. > Actually, allocating and disposing of memory within a pascal program doesn't go through the DOS memory manager. When your program is loaded by DOS, it is typically given control of all available memory unless you specify otherwise (by compiling with switches to limit memory consumption). After allowing for the space occupied by the program, static variables, and the stack, the rest of the memory DOS has allocated goes for TP's heap. Allocating and disposing dynamic variables is managed by TP's runtime library. When a program terminates, the memory allocated when it was initiated is automatically freed by DOS, so yes, it doesn't matter if you forget to dispose of some variables. As far as entering and exiting a program are concerned, then, it doesn't matter how the allocation is handled. However, it is important that while a program is running, Dispose() doesn't actually return anything to DOS's heap. There won't be any memory available for running another program from within a TP program, regardless of how empty TP's heap may be. Memory has to be explicitly freed for this purpose, either at compile time, or by shrinking a program's DOS memory allocation as soon as it starts to execute. I think there is a TP procedure to do this, but I don't remember the name. The information isn't obvious in the manuals; I think there is an index entry for "memory map" somewhere. - David Hinds dhinds@portia.stanford.edu