简体   繁体   中英

What happens when we run out of memory on an Cortex M3

I'm developing a program with C for an ARM processor, in my program when my memory usage grows(when the program flows through functions which have defined arrays in them) the program behaves unexpectedly and I think some variables are overwritten, that is when it runs out of memory it starts allocating memory from the beginning.

Now my question is : Is overwriting older variables the behavior it takes when there's lack of memory? If it is, how can I avoid this?

I'm using Keil uVision and lpc 1768.

Thanks for your helps.

Yes, You are right. When the stack memory is full it starts to fill it from bottom address(0x00..0).This causes older variables to be overwritten and program behaves unexpectedly. solution: The easiest way to solve this problem is never define array directly instead use malloc or calloc to allocate memory and free the memory as soon as possible. This can prevent memory from overwriting. It is also good practice.

1)Yes. over writing old variables happens due to lack of memory 2)To avoid this Try minimizing array size or you can increase the stack size. In Keil uVision there are options to increase stack size . This may solve your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM