L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual

Page 1084

Advertising
background image

L-force | PLC Designer

Programming Reference

1082

DMS 4.1 EN 03/2011 TD29

Syntax:
__NEW (<type>, [<size>] )
The operator will create a new object of the specified type <type> and returns a
pointer to that <type>. The initialization of the object is called after creation. If 0 is
returned the operation is failed.
If <type> is scalar the optional operand <length> has to be set additionally and the
operator creates an array of scalar types with the size length.
Example:

pScalarType := __New(ScalarType, length);

Note: A copy code in online change of dynamically created objects is not possible!

Therefore only function blocks out of libraries (because they can't change) and
function blocks with attribute 'enable_dynamic_creation' are allowed for the __New-
Operator.
If a function block change with this flag so that copy code would be necessary, an error
message is produced.

Note: The code for memory allocation needs to be non-reentrant.

A semaphor (SysSemEnter) is used to avoid two tasks try to allocate memory at the
same time. Thus, extensive usage of __New may produce higher jitter.

Example with a scalar type:

TYPE DUT :
STRUCT
a,b,c,d,e,f : INT;
END_STRUCT
END_TYPE

PROGRAM PLC_PRG
VAR
pDut : POINTER TO DUT;
bInit: BOOL := TRUE;
bDelete: BOOL;
END_VAR

Advertising