Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!hp4nl!dutrun!winfave From: winfave@dutrun.UUCP (Alexander Verbraeck) Newsgroups: comp.lang.pascal Subject: Strange... The Turbo Pascal NEW command Message-ID: <845@dutrun.UUCP> Date: 31 Jul 89 23:35:14 GMT Reply-To: winfave@dutrun.UUCP (A.Verbraeck) Organization: Delft University of Technology, The Netherlands Lines: 76 There's one thing about Turbo Pascal that I don't understand, and that is the how the New procedure knows the size of the block on the heap to be allocated. At this moment some of my students are working on a heap manager on top of the standard TP heap manager that allows 4 Gbyte of heap space using paging and virtual memory swapping pages to (Ram)disk, where it is *not* neccesary to change any existing code. You can still use the standard ^ types, New and Dispose. If there is any interest in this manager when it is finished, I can post it to the net (if-and-only-if we succeed of course). The problem is that we do not understand the way the New procedure works. When you call New(P) where P points to a certain type, the New procedure allocates the correct number of bytes on the heap. We think that the compiler inserts some extra parameters when calling New, for the following program works _NOT_ ok: program TestNew(input,output); const AS = 500; type TT = array[1..AS] of integer; PT = ^TT; var IP,JP : PT; i,j : integer; procedure New(var P); begin System.New(pointer(P)); end; begin writeln(MemAvail); New(IP); writeln(MemAvail); System.New(JP); writeln(MemAvail); for i:=1 to AS do IP^[i]:=i; for i:=1 to AS do JP^[i]:=0; for j:=1 to 10 do write(IP^[j]:5); writeln; write('Press Enter'); readln; end. Output of this program is for instance: ------------------------------------------------------------ 502314 502314 --> No memory allocated at all! 501314 --> 1000 bytes allocated 0 0 0 0 0 0 0 0 0 0 Press Enter ------------------------------------------------------------ Which means that no memory is allocated during the New call, the correct amount of memory is allocated during the System.New call, and IP and JP share Heap-memory. Does anyone know what parameters are passed extra to the New procedure? How can I use these parameters? Is it possible to make a customized version of the New procedure? How do I get it to pass the right parameters on to the System.New procedure? --------------------------------------------------------------------- Alexander Verbraeck e-mail: Delft University of Technology winfave@hdetud1.bitnet Department of Information Systems winfave@dutrun.uucp PO Box 356, 2600 AJ The Netherlands ---------------------------------------------------------------------