lyngaansns - 2022-04-08

I have found out that the __Delete function in codesys does not check if the given pointer is inside the memory space of the memory manager, this causes the program to crash if anything but a valid pointer from inside the memory space.

I have a case where I need to be able to do this safely, I can easily write a function which check before if the address is bigger than the start of the space and smaller than the end of the space, but then I need to know the start and end of the memory space.

The start I can extract by using the __NEW operator and then follow the chain of memory block headers to the first one.

The end I could hardcode, but then the function would not work across multiple project with differently assigned amounts of memory.

So my question is either if there is a built in way of achieving this, or if it is possible to get the size of the built in memory space during runtime?

Also as a side question, I am looking for a way to see the amount of used memory/amount memory left, because I would like to be able to warn the integrator when memory is usage is at 70%-80%, does such a functionality exist?

 

Last edit: lyngaansns 2022-04-08