VMS Help PASCAL, Predeclared Routines, Dyn Alloc, NEW *Conan The Librarian (sorry for the slow response - running on an old VAX) |
The NEW procedure allocates memory for the dynamic variable to which a pointer variable refers. The value of the newly allocated variable is set to the initial value of the base type if defined; otherwise, the value of the variable is undefined. Syntax: NEW( p [[, {t1,...,tn | d1,...,dn} ]] ) The parameter 'p' is a pointer variable. The parameters 't1,...,tn' are constant expressions of an ordinal type that represent nested tag-field values, where 't1' is the outermost variant. If the object of the pointer is a non-schema record type with variants, then you have two ways of allocating memory. If you do not specify 't' parameters, Compaq Pascal allocates enough memory to hold any of the variants of the record. If you do specify 't' parameters, then Compaq Pascal allocates enough memory to hold only the variant or variants that you specify. Since the 't' parameters cause Compaq Pascal to allocate memory for the variant alone and not for the whole record, you cannot assign or evaluate the record as a whole; you can assign and evaluate only the individual fields. Also, a call to NEW does not set the tag fields of a variant record. The paramters 'd1,...,dn' are compile-time or run-time ordinal values that must be the same type as the formal discriminants of the object. If the object of the pointer is of an undiscriminated schema type, you must specify a 'd' parameter for each of the formal discriminants of the schema type. The 'd' parameters discriminate the schema type in much the same way as actual discriminants in a discriminated schema. Compaq Pascal bases the size of the allocation on the value of the 'd' parameters. If the object is a schema record type, then you must use 'd' parameters; you cannot use 't' parameters or a combination of the syntaxes. If the schema record type contains a variant (which depends on one of the formal discriminants) then the 'd' parameter discriminates the schema, determines the variant, and allows Compaq Pascal to compute the necessary size of the allocation. Note that if you specify 't' parameters to the NEW procedure, you must specify the same 't' parameters to the DISPOSE procedure that deallocates memory for the corresponding variable.
|