Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!ut-sally!ut-ngp!ayac071 From: ayac071@ut-ngp.UUCP (William T. Douglass) Newsgroups: comp.lang.pascal Subject: Re: implementing large arrays in turbo pascal Message-ID: <6564@ut-ngp.UUCP> Date: Sun, 18-Oct-87 15:07:43 EDT Article-I.D.: ut-ngp.6564 Posted: Sun Oct 18 15:07:43 1987 Date-Received: Mon, 19-Oct-87 00:24:05 EDT References: <9834@brl-adm.ARPA> Reply-To: ayac071@ngp.UUCP (Bill Douglass) Organization: UTexas Computation Center, Austin, Texas Lines: 70 In article <9834@brl-adm.ARPA> 16448591%VUVAXCOM.BITNET@wiscvm.wisc.EDU writes: >Subject: implementing large arrays in turbo pascal > > >in <973@cup.portal.com> you write: >>I need some help in writing a turbo pascal program. What I am >>trying to do is to write an image processing program that >>will be able to do image compression and enhancement. The >>problem i run across is the memorylimit in turbo, and in >>having a clean way of implementing a large matrix in turbo. >> > >The only way I know to get around turbo pascal's memory limit with large >arrays is to create an array that is really a structure referenced through >a pointer. For example, suppose the following types are defined in a program: > >array_type = array[0..45000] of real; >array_ptr = ^array_type; > >These type statements set up the type for the array and a pointer to it. > Sorry, Mark, but this won't work. 1st, TP only supports constants up to the size MAXINT, which is 32,767 (signed 16-bit quantity, called INTEGER in TP.) Secondly, an array of that many reals cannot fit in a single 8086 segment of 64K. This is a constraint on all data structures running on IBM-PC type machines. I recommend creating an array of pointers to arrays, with each individual array under 64K bytes in size. One way to do this is: type bigarray = array[0..1] of real; (* or whatever type is needed *) var a1,a2: array[0..1000] of ^bigarray; begin getmem(a1,NUM_OF_BYTES_NEEDED); getmem(a2,NUM_OF_BYTES_NEEDED); a1[1]^[1] := value1; (* 1st element of 1st array *) a1[1]^[2] := value2; (* 2nd " " " " *) a1[2]^[1] := value3; (* 1st element of 2nd array *) You're matrix is not stored contiguously in memory, but should function as a regular matrix for most purposes. Caveats: You must use pointer indirection to access to 2nd array index i.e. a1[n]^[m] You have to calculate the size needed in bytes when using getmem. You could say GETMEM(A1,SIZEOF(REAL)*NUM_OF_BYTES_NEEDED); You cannot do i/o directly on dynamically-allocated data structures. You have to input your values, then assign them to the appropriate element. Each "ROW" can only be 64K-bytes long. You need enough memory to allocate the arrays, lest you get 0-value pointers and start storing data on top of the interrupt vectors. Best to use the TP function MEMAVAIL to check of the amount of heap memory available before doing the getmem() call. If you want to discuss this further, drop me a line. Bill Douglass ayac071@ngp.UUCP