Is there a way to detect when an array (or any variable) will be larger than the amount of free memory in the system? Secondarily, if such an variable was declared, what would happen?
Some background: I'm on an embedded ARM device with 20KB of RAM; it is not running an RTOS. I'm trying to read sensor data out into arrays, but there's a significant amount of sensor data that can be read. If I was allocating the memory with malloc, I could check that the return != NULL to see if enough space on the heap was available (though this question seems to indicate that might be optimistic). However, I'm not sure what happens when an array that is larger than the available memory is declared.
The obvious solution is to do what the linked question's accepted answer states: allocate all of the memory for the data upfront. But if declaring arrays dynamically, how could one tell if the system was out of memory, and what would happen if one didn't?
edit: Some examples, to illustrate what I'm referring to. What would happen if one defined an array like so:
void breaking_things(){
uin8_t contrived_example[30000] = {0};
}
This isn't possible on my system where I only have 20KB of free space, but what will happen.
As another example:
void breaking_things(){
uin8_t contrived_example0[7000] = {0};
uin8_t contrived_example1[7000] = {0};
uin8_t contrived_example2[7000] = {0};
}