Toby Ewing wrote:
Hi, all The problem in the old compiler is a crash when writing.
The reason for the program approach is this: I'm trying to distribute a program where the user specifies a matrix size in the input file, so I can distribute a binary and users don't need to have a compiler in order to resize the matrix. I've worked with this memory model before, and it worked fine. But now I'm having trouble, and I don't see the problem.
many thanks for the old and new compilers, which make my work possible. Toby
program testmem;
const Xmax = 25;
type Fieldary = array[1..2] of real; FPary = array[0..Xmax] of ^Fieldary;
var Field : FPary; FSize, i,j, k, nx : integer;
begin writeln; write('Enter the size: '); {I used 5} readln(nx); FSize := 8 * sqr(nx); {making a cube. *8 is for "real"}
^^^^
It is a square not a cube ? try
8 * nx pow 3
In addition you should write SizeOf(Real) instead of 8 to make this portable
for i := 0 to nx do GetMem(Field[i], FSize); writeln('Memory allocated OK'); for i := 0 to nx do for j := 1 to nx do for k := 1 to nx do Field[i]^[j+(nx*k)] := 1.0 * i * j * k; writeln('Done assigning. Writing...'); for i := 0 to nx do for j := 1 to nx do begin for k := 1 to nx do write(Field[i]^[j+(nx*k)]:8:1, ' '); {<== CRASHES HERE with a GPF} writeln; end; writeln('Freeing memory...'); for i := 0 to nx do if (Field[i] <> Nil) then FreeMem(Field[i]); end.
Maurice