next up previous contents
Next: 3.4 File Types Up: 3. Data Types Previous: 3.2 Composite Types

3.3 Access Types

Data objects of the type access are pointers to dynamically allocated scalar or complex data objects. They are similar to pointers in other programming languages (C or Pascal). Only a variable can be declared of type access.

Syntax:
type ptr_type_name is access type_name;
In order to allocate and deallocate memory for an access type variable two operators are defined:

New:
This function is used to allocate memory for the object to which a variable of type access is pointing. It is, therefore, used in conjunction with an assignment to an access type variable. Initial values for the newly created object can be explicitly specified.

If the access type variable is pointing to an unconstrained type like string then the restriction must be defined within the function call new.

Deallocate:
This procedure is provided to free the memory allocated for the object to which an access type variable is pointing.

Example:
type CELL;                           
incomplete type
type LINK is access CELL;                
access type
type CELL is          
full type declaration for CELL
  record
    VALUE : integer;
    NEXTP : LINK;
  end;
variable HEAD, TEMP : LINK;          
pointer to CELL
...
TEMP := new CELL'(0, null);   
new data object with initial values
for I in 1 to 5 loop
  HEAD := new CELL;               
additional objects
  HEAD.VALUE := I;          
access to record element
  HEAD.NEXTP := TEMP;
  TEMP := HEAD;
end loop;
...
deallocate(TEMP);                    
free the memory

allocate new memory
new CELL;                                 
new object
new CELL'(I, TEMP);     
... with initial values

... with the required range restriction
new BIT_VECTOR (15 downto 0);   
by specifying an index range
new BIT_VECTOR'("001101110");   
by assigning an initial value


next up previous contents
Next: 3.4 File Types Up: 3. Data Types Previous: 3.2 Composite Types
Richard Geissler
1998-10-07