uses crt type ptr worker worker record name string age integer end vec

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
uses crt;
type ptr = ^worker;
worker = record
name:string;
age:integer;
end;
vect = array[1..10] of integer;
matrix = array[1..3,1..3] of integer;
var p:pointer;
pi:^integer;
pr:^real;
ps:^string;
pa:^vect;
pm:^matrix;
pw:^worker;
pBigArray:^integer;
i:integer;
r:real;
s:string;
a:vect;
m:matrix;
w:worker;
n1,n2:integer;
count:longint;
worker1:ptr;
begin
clrscr;
writeln('********** Test integer **********');
writeln('Static int = ',sizeof(i));
writeln('Pointer int = ', sizeof(pi));
n1:=memAvail;
new(pi);
n2:=memAvail;
writeln('Heap int = ',n1-n2);
dispose(pi);
writeln;
writeln('********** Test real **********');
writeln('Static real = ',sizeof(r));
writeln('Pointer real = ', sizeof(pr));
n1:=memAvail;
new(pr);
n2:=memAvail;
writeln('Heap real = ',n1-n2);
dispose(pr);
writeln;
writeln('********** Test string **********');
writeln('Static string = ',sizeof(s));
writeln('Pointer string = ', sizeof(ps));
n1:=memAvail;
new(ps);
n2:=memAvail;
writeln('Heap string = ',n1-n2);
dispose(ps);
writeln;
writeln('********** Test vector **********');
writeln('Static vector = ',sizeof(a));
writeln('Pointer vector = ', sizeof(pa));
n1:=memAvail;
new(pa);
n2:=memAvail;
writeln('Heap vector = ',n1-n2);
dispose(pa);
writeln;
writeln('********** Test matrix **********');
writeln('Static matrix = ',sizeof(m));
writeln('Pointer matrix = ', sizeof(pm));
n1:=memAvail;
new(pm);
n2:=memAvail;
writeln('Heap matrix = ',n1-n2);
dispose(pm);
writeln;
writeln('********** Test worker **********');
writeln('Static worker = ',sizeof(w));
writeln('Pointer worker = ', sizeof(pw));
n1:=memAvail;
new(pw);
n2:=memAvail;
writeln('Heap worker = ',n1-n2);
dispose(pw);
writeln;
writeln('********** Test big array **********');
write('Enter size of array (count elements): ');
readln(count);
n1:=memAvail;
writeln('maxAvail = ',maxAvail);
writeln('need memory = ',count*sizeof(integer));
if(MaxAvail >= count*sizeof(integer)) then
begin
getMem(pBigArray,count*sizeof(integer)) ;
freeMem(pBigArray,count*sizeof(integer));
n2:=memAvail;
writeln('Heap bigArray = ',n1-n2);
end
else writeln('Not enough memery');
writeln;
writeln('********** Test mark-release **********');
new(pi);
mark(pi);
new(pr);
new(ps);
release(pi);
{
dispose(pr);
dispose(ps);
}
writeln;
readkey;
end.