Do i need to memrelease?

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):wink:

#include "adl_global.h"

const u16 wm_apmCustomStackSize = 1024;

void HelloWorld_TimerHandler ( u8 ID, void * Context )
	char tstring[20] = "Joke";
	char fstring[20] = "call" ;
	strcat (tstring,fstring);
    /* Hello World */
    TRACE (( 1, "Embedded : Hello World" ));
    adl_atSendResponse ( ADL_AT_UNS, tstring);
    adl_atSendResponse ( ADL_AT_UNS, "\r\nLow bit sent\r\n" );
void adl_main ( adl_InitType_e  InitType )
    TRACE (( 1, "Embedded : Appli Init" ));
    adl_atSendResponse ( ADL_AT_UNS, "\r\nAppl start\r\n" );
    /* Set 1s cyclic timer */
    adl_atSendResponse ( ADL_AT_UNS, "\r\nHIGH BIT SENT\r\n" );
    adl_tmrSubscribe (TRUE, 100, ADL_TMR_TYPE_100MS, HelloWorld_TimerHandler );


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.

Hope this helps.

ciao, Dave

No, you don’t.

This is basic, standard, textbook ‘C’ - nothing specifically to do with Wavecom or Open-AT.

You need to go right back to basics and look again a writing functions in ‘C’ having local - or “automatic” - variables…

Here are some general books about ‘C’ programming:

See also:


And: … efix=c+pro