SysMAlloc has 4096 bytes of reserved memory, every time the function is called the specified amount of memory is subtracted from the total memory available. The function returns the pointer to the allocated memory (Type @USINT), if there’s no space available NULL is returned.
SysMAlloc can be called all time you need a memory buffer, but remind that the allocated memory cannot be released. So every time the function is called the specified amount of memory is subtracted from the total memory available. All the SysMAlloc memory is released when user program starts.
SysRMAlloc has 20 KBytes of reserved memory, every time the function is called the specified amount of memory is subtracted from the total memory available. A UDINT buffer is needed by the function to store the pointer to the allocated memory. If there’s no space available the UDINT buffer is set to NULL and FALSE is returned. Instead of the SysMAlloc, the allocated memory can be released by calling the SysRMFree function.
Note that SysRMAlloc uses a completely different allocation mechanism than SysMAlloc, the allocated memory is moved run time by the operating system to optimize the memory space. This obviously causes that the pointer to the allocated memory can be modified (For this reason a buffer to store it is necessary).
So every time a buffer allocated by SysRMAlloc is used it’s mandatory to refer to the address stored in the UDINT buffer passed to it and it’s not possible to use copies of it.
Pointers returned by SysMAlloc e SysMAlloc are aligned so no alignment is needed, obviously when a misaligned buffer is allocated, with the next call, up to 3 bytes of memory can be lost.