Router memory

Compared to conventional control systems, image processing applications require a lot of memory, because even a single image can contain several megabytes of data. In TwinCAT Vision, all dynamic data (see Interface Pointer) are allocated in the router memory. For this reason, it is particularly important to configure the size of the router memory accordingly. It can be set in the TwinCAT system configuration under the Real-Time node in the Settings tab:

Router memory 1:

Configured Size

Setting of the router memory required for the current project.

Allocated

Router memory currently allocated on the system.

Available

The part of the router memory currently allocated on the system that is still freely available. (The rest is already used within TwinCAT.)

If the available memory is not fully restored following a TwinCAT restart, this points to a memory leak. In that case, restart your system and check your program with regard to memory leaks.

The maximum adjustable size of the router memory in TwinCAT 3.1 4024 is 1024 MB. From TwinCAT 3.1 4026, the usable size essentially depends on the available main memory and is limited to 65535 MB. The actually required memory size depends among other things on the use of dynamic memory (e.g. with images and containers) in the PLC program.

Notice

Size of the router memory

When configuring the router memory, it must be noted that the router memory will be subtracted from the main memory and is thus no longer available to the operating system. Therefore we recommended avoiding the size of 1024 MB in systems with a main memory size of less than 4 GB. With external projects, always check the router memory setting before activating the configuration and reduce it if necessary.

Estimating the required memory size

The required size of the router memory depends on many factors. A rough estimate for the Vision part of the TwinCAT project can be obtained by calculating the memory dynamically allocated (by Interface Pointers).

The storage space M (in bytes) of an image can be calculated by incorporating the image size (width w and height h), number of channels C and the number of bytes of the element type: M = w * h * C * sizeof(ElementType).

For a container of the type String or Vector, the storage space M (in bytes) can be calculated through the number of allocated elements N and the number of bytes of the element type: M = N * sizeof(ElementType).

Attention must be paid to how the data are copied and released. If an image is copied or a new one is generated, the storage space for both instances must of course be included in the calculation. Moreover, the memory requirement of the router itself and other project parts must be included in the calculation. When retrieving the images or other data via ADS, these are copied, so additional storage space must also be taken into account for this.

Notice

Memory value with safety factor

Always extend the calculated memory value with a safety factor. Also take into account the memory requirement of the other modules in the project.

So as not to use an unnecessarily large amount of space in the router memory, you should take care not to make any unnecessary deep copies and to release objects again that are no longer required (see Interface Pointer). In order to find out how much memory is actually being used, the router memory can be monitored live as follows.

Monitoring the router memory

Even if the router memory is set in the project, this is a system-wide setting. Therefore, the router memory set in the project and currently used on the system can be viewed on the target system. To do this, right-click the TwinCAT icon in the Windows taskbar and select Router > Info.

Router memory 2:
Router memory 3:

Notice

Reduction of the available router memory

The available router memory may be reduced through Exceptions or unreleased Interface Pointers. Therefore, the memory should be checked during the development, in particular in the case of an error. If not enough memory is available, restart the complete system and then check your program.