NEW - dynamically allocate memory.

Usage:

var
    p : ^ TYPE;
  ...
new(p);

Where:

p
is a pointer to any valid type.

Description:

The "new" procedure allocates enough memory to hold a data object of type TYPE and points the pointer "p" towards this memory. For example, in

var
    pi : ^ integer;
  ...
new(pi);

"new" will allocate enough memory to hold an integer and then point "pi" towards the newly allocated memory.

Complications arise when allocating memory for a record variable that has a variant part. Different variations may require different amounts of memory, and therefore "new" needs a technique to determine how much memory is actually required. You do this with a call of the form

new(p,t1,t2,...,tN);

where the arguments "t1", "t2", etc. are values for tag fields in the record being allocated. "new" will use these values to determine which variation of the record is being used, and therefore how much memory should be allocated.

You may omit some trailing tag field specifications if you wish. For example, suppose a record has three tag fields. You may specify tags one and two, and omit tag three. In this case, the "new" procedure will allocate enough space to hold the longest variation of the record that has tags one and two as specified. If you omit all tag fields, "new" will allocate enough memory to hold the largest possible variation of the record.

Note that you may only omit TRAILING tag fields. For example, you cannot omit tag two but put in tags one and three. If you omit a particular tag, you must also omit all the tags that come after that one.

See Also:

expl pascal lib dispose

Copyright © 1996, Thinkage Ltd.