GET_NAMED_MEMORY block

Short summary

Name

GET_NAMED_MEMORY

→POU type

→function

Category

IEC-block, MemoryEnh, block with internal error diagnostic

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/add.svg not defined in IEC-standard

Graphical interface

images/download/thumbnails/414781810/GET_NAMED_MEMORY-version-1-modificationdate-1535026928658-api-v2.png

Available since

  • version 1.38.0 (for logi.CAD 3) and version 2.3.1602 of logi.RTS
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/warning.svg This block is supported for the built-in PLC only.

  • version 1.109.0 (for logi.CAD 3) and version 3.19.0 of logi.RTS: returns the reference to the same memory area as GET_NAMED_MEMORY_RETAIN
    images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/warning.svg This block is supported for the built-in PLC and the platforms WindowsX86 and LinuxX86 only.

  • version 3.2.2 (for library Standard) – enhancement: reference to STRING and CHAR for the return value; returns the reference to a different memory area than GET_NAMED_MEMORY_RETAIN

Functionality

The block returns the →reference to a memory area the name of which you enter at input NAME.

When the block is called for the first time, the requested memory in the dynamic memory of the target system (heap) is allocated and a reference to it is returned. The memory area referenced by the return value is initialized with 0 during the request. For each subsequent call of the block, a reference to the already allocated memory is returned.
In case of a →cold restart or →warm restart of the application, an allocated memory is automatically released.

As the type information of the return value is saved in addition to the name of the memory area, it is only allowed to use the call of the block on the right side of the assignment operator ":=" for →assignments to a reference variable. The size of the memory area results from the data type of the reference variable.

Inputs, outputs, return value


Identifier

→Data type

Description

Inputs:

NAME

STRING

name of the memory area

Outputs:

RC

USINT

return code of the allocation:

  • 16#00: allocation succeeded

  • 16#01: out of memory error

  • 16#02: The requested data type does not match.

  • 16#FF: The service is not available.

Return value:

a →reference to the following data types:
REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, TIME, BOOL, BYTE, WORD, DWORD, LWORD, STRING , CHAR , DATE_AND_TIME, DATE, TIME_OF_DAY or a →user-defined data type
Restriction: In case of →array data types, only one-dimensional arrays are allowed.

typed reference to the requested memory area or NULL

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Internal error diagnostic for block

The block checks the following error cases:

  • The target system is out of memory.

  • The data type of the variable to which the call has been assigned does not match the data type of the memory area.

  • The RTSSMem system service has not been loaded.

In such an error case, the output ENO of the block is set to value FALSE (or an equivalent). Moreover, the output RC returns the appropriate code (see the above table under RC) and the block itself returns NULL (as return value).

Example for usage within ST-editor

Exemplary usage of the GET_NAMED_MEMORY block
PROGRAM GET_NAMED_MEMORY_TEST
VAR
r_data : REF_TO DWORD;
r_other : REF_TO DWORD;
r_invalid : REF_TO LWORD;
eno_data : BOOL := FALSE;
eno_other : BOOL := FALSE;
eno_invalid : BOOL := FALSE;
rc_data : USINT := 0;
rc_other : USINT := 0;
rc_invalid : USINT := 0;
END_VAR
r_data := GET_NAMED_MEMORY(NAME := 'data', ENO => eno_data, rc => rc_data);
IF eno_data THEN
r_data^ := 16#01020304;
END_IF;
r_other := GET_NAMED_MEMORY(NAME := 'data', ENO => eno_other, rc => rc_other);
IF eno_data AND eno_other THEN
/* 'r_data_other' now refers to the same memory area as 'r_data' */
END_IF;
r_invalid := GET_NAMED_MEMORY(NAME := 'data', ENO => eno_invalid, rc => rc_invalid);
/* 'r_data_invalid' is 'NULL' because types do not match; 'ENO' is 'FALSE', 'rc' has value '16#02' */
END_PROGRAM

logi.cals recommends to call the GET_NAMED_MEMORY block once at the most for each memory area to request. On the one hand the time behavior might be unpredictable and on the other hand it might take longer to determine the already allocated memory area. The following example demonstrates the one-time usage:

Recommended usage of the GET_NAMED_MEMORY block
PROGRAM GET_NAMED_MEMORY_RECOMMENDED
VAR
r : REF_TO BYTE := NULL;
rc : USINT := 16#FF;
END_VAR
IF r = NULL THEN
r := GET_NAMED_MEMORY(NAME := 'sample', ENO => ENO, RC => rc);
END_IF;
IF ENO THEN
/* code using the reference to the allocated byte */
r^ := 16#AF;
END_IF;
END_PROGRAM

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.