Memory allocation

Generally we recommend reserving memory with the aid of member variables of the module class. This is done automatically for data areas defined in the TMC editor.
It is also possible to allocate and release memory dynamically.

This memory allocation can be used in the transitions or in the OP state of the state machine.

If the memory allocation is made in a non-real-time context, the memory is allocated in the non-paged pool of the operating system (blue in the diagram). In the TwinCAT real-time context, the memory is allocated in the router memory (red in the diagram).

The memory can also be released in the transitions or the OP state; we recommend to always release the memory in the "symmetric" transition, e.g. allocation in PS, release in SP.

Memory allocation 1:

When using static variables, some special features have to be considered, which are documented here.