VSI Pascal provides dynamic allocation routines for the creation and use of pointer variables. Use pointer variables and dynamic allocation routines to create linked data structures.
1 – ADDRESS
The ADDRESS function returns a pointer value that is the address of the parameter. Syntax: ADDRESS( x ) The parameter 'x' can be a variable of any type except a component of a packed structured type. A compile-time warning results if 'x' is a formal VAR parameter, a component of a formal VAR parameter, or a variable that does not have the READONLY or VOLATILE attribute. A pointer can only refer to a VOLATILE variable or a variable allocated by the NEW procedure.
2 – DISPOSE
The DISPOSE procedure deallocates memory for a dynamic variable. Syntax: DISPOSE( p ) The parameter 'p' is a pointer variable. The 't' parameters are constant expressions that match the corresponding 't' parameter used in the call to the NEW procedure that allocated the memory. If you use 't' parameters in a call to NEW, you must specify the same 't' parameters in the call to DISPOSE. If you allocated memory using d parameters, just specify the pointer variable to the corresponding DISPOSE call. The DISPOSE procedure deallocates the object to which the pointer variable points. You cannot call DISPOSE more than once for the same dynamic variable.
3 – IADDRESS
The IADDRESS function returns an INTEGER_ADDRESS value that refers to a the address of either a VOLATILE parameter or a routine, and does not generate compile-time warnings (as does the ADDRESS function). The IADDRESS function is commonly used for constructing arguments for system services of the OpenVMS operating system. Syntax: IADDRESS( x ) The parameter 'x' can be of any type except a component of a packed structured type or a routine name. The parameter 'x' can be a variable, parameter, routine, or constant-expression. When IADDRESS is used on constant-expressions, the returned address is valid for the remainder of the program. Two calls to IADDRESS with the same constant may not return the same address. Note that the VSI Pascal compiler automatically assumes that all pointers refer either to dynamic variables allocated by the NEW procedure or to variables that have the VOLATILE attribute; therefore, you should use utmost caution when using the IADDRESS function. This function does not generate compile-time warnings.
4 – IADDRESS64
The IADDRESS64 function is essentially identical to the IADDRESS function with the exception that IADDRESS64 returns an INTEGER64 result. This does not force the parameter of IADDRESS64 into 64-bit address space but simply returns the address of the parameter as an INTEGER64 value. Syntax: IADDRESS64( x ) The parameter 'x' can be of any type except a component of a packed structured type or a routine name. The parameter 'x' can be a variable, parameter, routine, or constant-expression. When IADDRESS is used on constant-expressions, the returned address is valid for the remainder of the program. Two calls to IADDRESS64 with the same constant may not return the same address. Note that the VSI Pascal compiler automatically assumes that all pointers refer either to dynamic variables allocated by the NEW procedure or to variables that have the VOLATILE attribute; therefore, you should use utmost caution when using the IADDRESS function. This function does not generate compile-time warnings.
5 – NEW
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 32-bit pointer variable. On OpenVMS Alpha and OpenVMS I64, the parameter 'p' may also be a 64-bit 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, VSI Pascal allocates enough memory to hold any of the variants of the record. If you do specify 't' parameters, then VSI Pascal allocates enough memory to hold only the variant or variants that you specify. Since the 't' parameters cause VSI 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. HP 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 VSI 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. If the parameter 'p' is a 64-bit pointer variable, the NEW procedure will call LIB$GET_VM_64 to allocate memory from "P2" space. Likewise, DISPOSE of a 64-bit pointer expression will call LIB$FREE_VM_64 to return the memory.