How do I know when my memory is full?

I am writing firmware for the Atmel XMEGA microcontroller in c, and I think I filled 4k SRAM. As far as I know, I only have static / global data and local stack variables (I don't use malloc in my code).

I use a local variable to buffer some pixel data. If I increase the buffer to 51 bytes, strange results will appear on my display - a buffer of 6 bytes works fine. That's why I think my ram is full and the stack is rewriting something.

Creating more free memory is not my problem, because I can just move some static data into flash memory and load it only when necessary. My concern is the fact that I could never find out that the memory is full.

Is it possible to somehow cut (for example, by reselling the microcontroller) when the memory is full, instead of allowing it to overwrite some other data?

+3
source share
4 answers

, ( , , - ).

, , /, , .

.

, : , , , ( , ).

, , , "" / , , . .

+3

"- (, ), ?"

, , (1). / , (*).

- , (2). , addr (*). ( AVR) reset/trap (= , ).

  [not mapped addr space][   RAM  mapped  addr  space   ][not mapped addr space] 
(1)                      [variables --->  *   <--- stack] 
(2)                     *[ <--- stack   variables --->  ]* 

( , /)

, , .

+1

, , , . ( ) , , .

, , , .

(), , .

  • ( ), , .
  • ( ) ,

, , , , , , - ...

+1

Usually your programming tool knows the parameters of the controller, so you should warn if you used more (without mallocs, this is known at compile time).

But you have to be careful with pixeldata, because most displays do not have a linear address space.

EDIT: usually you can specify the stack size manually. Leave enough memory for static variables and reserve the rest for the stack.

0
source

Source: https://habr.com/ru/post/1774045/


All Articles