Using the following code as a sample, since every 1 sec the HelloWorld_TimerHandler function is called, tstring and fstring will be redeclared. As such do i need to (adl_memRelease()) for both strings?
The code doesnt run if i use memRelease, the wirless cpu resets at that code (adl_memRelease(tstring)
Iām not surprised. This is a pretty basic C misconception that arrays and pointers are equivalent. In some respects they can be treated the same, but they are not equivalent.
You have declared your tstring and fstring variables as stack variables of a constant length. As stack variables, they will be ācleaned upā when the function call is completed.
Yes, the variables will be āre-allocatedā - but on the stack, not on the heap. There is nothing wrong with doing this - but just remember that you have told the compiler how much stack space you require when you set the stack size using
const u16 wm_apmCustomStackSize = 1024;
in your main source file. If you allocate too many variables (and remember every variable defined in a function is stored on the stack), or have too many levels of function calls, you can have a stack overflow - which will also reset your processor. Stack overflow resets can be quite difficult to track down. This is why you should use adl_memGet() and adl_memRelease() to allocate/deallocate pointers for large buffers or data structures, rather than creating them as local variables (which end up on the stack).
Remember, adl_memGet() is equivalent to malloc() and adl_memRelease() is equivalent to free(). Because you havenāt adl_memGet()'d the memory, you donāt have to adl_memRelease() it. The CPU is resetting because you are trying to release memory that was never allocated.
Itās probably worth your while getting out your favorite C textbook and going over the section on pointers again.