On LogicLab programmable systems we provide two ways to allocate dynamic memory, in the allocated memory buffer it’s possible to store any kind of data but it’s not possible to instantiate FBs. The LogicLab compiler istantiates FBs only in data memory area.
SysMAlloc: This function allocate static dynamic memory and returns its address. There’s a dedicated RAM area on wich the function operates, this area is cleaned at program starting, the function reserves the defined size of memory and returns its address. The allocated area cannot be removed, it still allocated until a the program stops.
SysRMAlloc: This function allocate relocatable dynamic memory and returns its address on a pointer variable. Calling the function if the desired space of memory is available it’s cleaned and the address is saved in the defined buffer. By calling SysRMFree function the buffer is released so the memory can be reused. A proprietary garbage collector operates on the memory moving allocated buffers recovering free spaces optimizing memory use. For this reason the returned address can change during program execution and it’s necessary refer to it anytime before to use it.
So you cannot store FBs on relocatable memory, but if your own FBs use large amount of data for store variable or strings you can use SysRMalloc to create space for them on relocatable memory and freee the space after use. Many of our FBs use this technique to save memory, for example FIFOFile can be set to use dynamic memory to store the file. Since the file on the memory must be used for ever the SysRMalloc is used to allocate it.
In the ST_SendFileByEMail example program the SysRMAlloc function is used to allocate space to save the email body, when the eMail is sent the used memory can be relased.