Maurice Lombardi wrote:
Toby Ewing wrote:
FSize := 8 * sqr(nx); {making a cube. *8 is for "real"}
^^^^
It is a square not a cube ? try
8 * nx pow 3
No, the first index (i) covers one dimension, the second index the other two. I don't know why it's done this way, but generally the square here is correct.
for i := 0 to nx do GetMem(Field[i], FSize);
In addition you should write SizeOf(Real) instead of 8 to make this portable
Definitely.
Anyway, the real error is in the index computations. I won't tell you exactly where, since you might learn more if you find out yourself. ;-) But you don't actually have to, since using a schema type is not only easier and avoids the difficult size and index computations, but also avoids the upper limit.
program testmem;
type Fieldary (Size: Integer) = array [0 .. Size, 1 .. Size, 1 .. Size] of real;
var Field : ^Fieldary; i,j, k, nx : integer;
begin writeln; write('Enter the size: '); {I used 5} readln(nx); New (Field, nx); 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, 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, k]:8:1, ' '); writeln; end; writeln('Freeing memory...'); Dispose (Field) end.
Frank