Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Pascal/HP-UX Programmer's Guide > Chapter 6 Dynamic Variables

Dispose Procedure

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

The predefined procedure dispose takes a pointer variable as a parameter and deallocates the dynamic variable that it references. When the variable is deallocated, it is inaccessible, and the pointer is undefined. Files in the deallocated space are closed.

The procedure new can only reallocate the space that dispose has deallocated if the program contains the compiler option HEAP_DISPOSE. For more information, refer to the HP Pascal/iX Reference Manual or the HP Pascal/HP-UX Reference Manual, depending on your implementation.

It is an error to call dispose with a pointer that is:

  • Undefined.

  • Nil.

  • The dynamic variable referenced by a pointer that is the actual parameter, passed by reference, of a currently executing routine.

  • The dynamic variable referenced by a pointer that is in the record variable list of a currently executing WITH statement.

Example 1

PROGRAM prog;
TYPE
rec = RECORD
f1,f2,f3 : integer;
END;

recptr = ^rec;
VAR
v1,v2,v3,v4,v5 : recptr;

PROCEDURE p (VAR x : rec);
BEGIN
dispose(v4); {illegal disposes x's actual parameter}

END;

PROCEDURE q;
BEGIN
dispose(v4); {illegal v4^ is in the record variable
list of an active WITH statement}
END;
PROCEDURE r (VAR z : recptr);
PROCEDURE s;
BEGIN
dispose(v4); {illegal v4^ is the actual parameter for z}
END;
BEGIN
s;
END;
BEGIN
new(v1);
WITH v1^ DO BEGIN
f1 := 0;
f2 := 0;
f3 := 0;
END;
dispose(v1);
dispose(v1); {illegal v1 is undefined}

new(v2);
dispose(v2);

new(v3);
v3 := nil;
dispose(v3); {illegal v3 is nil}

new(v4);
p(v4^);

new(v4);
r(v4); {s (within r) disposes r's actual parameter v4,
which is illegal}
new(v4);
new(v5);
WITH v4^,v5^ DO BEGIN
f1 := 1;
f2 := 2;
f3 := 3;
q; {illegal q disposes v4 while the WITH statement
whose record variable list it is in
is active}

dispose(v5); {illegal v5 is in the record variable list
of an active WITH statement}
END;
END.

If you specify tags when you allocate a variable with new, you must specify the same tags in the same order when you deallocate the variable with dispose.

Example 2

PROGRAM prog;

TYPE
rec = RECORD
CASE t1 : (a,b) OF
a : (a1,a2 : integer);
b : (b1 : RECORD
CASE t2 : (c,d) OF
c : (c1 : char);
d : (d1,d2 : real);
END
);
END;

recptr = ^rec;

VAR
v1,v2,v3,v4,v5 : recptr;

BEGIN
new(v1);
new(v2,a);
new(v3,b);
new(v4,b,c);
new(v5,b,d);

dispose(v1);
dispose(v2,a);
dispose(v3,b);
dispose(v4,b,c);
dispose(v5,b,d);

new(v1);
new(v2,a);
new(v3,b);
new(v4,b,c);
new(v5,b,d);

dispose(v1,a); {illegal a not specified on new}
dispose(v2,b); {illegal b not specified on new}
dispose(v3); {illegal b specified on new, but not here}
dispose(v4,b); {illegal c specified on new, but not here}
dispose(v5,d,b); {illegal b and d are in the wrong order}
END.
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.