Dynamic memory allocation functions

The following functions enable the dynamic allocation of arrays for storing DINT integer values:

ARCREATE allocates an array of DINT integers
ARREAD  
read a DINT integer in an arrayallocated by ARCREATE
ARWRITE 
write a DINT integer in an arrayallocated by ARCREATE

Important notes

  • The memory used for those arrays is allocated directly by the Operating System of the target. There is no insurance that the required memory space will be available.
  • Allocating large arrays may cause the Operating System to be instable or slow down the performances of the target system.

  • Dynamic memory allocation may be unsuccessful (not enough memory available on the target). Your application should process such error cases in a safe way.

  • Dynamic memory allocation may be not available on some targets. Please refer to OEM instructions for further details about available features.

ARCREATE: array allocation

OK := ARCREATE (ID, SIZE);

ID : DINT   integer ID to be assigned to the array (first possible ID is 0)
SIZE : DINT
wished number of DINT values to be stored in the array
OK : DINT  
return check

Return values

1    OK - array is allocated and ready for read / write operations
2   
the specified ID is invalid or already used for another array
3   
the specified size is invalid
4   
not enough memory (action denied by the Operating System)

The memory allocated by ARCREATE will be released when the application stops.

ARREAD: read array element

VAL := ARREAD (ID, POS);

ID : DINT   integer ID of the array
POS : DINT 
index of the element in the array (first valid index is 0)
VAL : DINT 
value of the specified item or 0 if arguments are invalid

ARWRITE: write array element

OK := ARWRITE (ID, POS, IN);

ID : DINT   integer ID of the array
POS : DINT 
index of the element in the array (first valid index is 0)
IN : DINT  
value to be assigned to the element
OK : DINT  
return check

Return values

1    OK - element was forced successfully
2   
the specified ID is invalid (not an allocated array)
3   
the specified index is invalid (out of array bounds)