I’m new to android programming. I have a native C application that I am building with NDK-Build. I am doing a static allocation in one of the threads.
int X[64][4096]; //<– exactly 1 MB space required.
When i run this using an adb shell, I get a “segmentation fault”. If I reduce the array to just X[63][4096], it seems to run fine. Now I know there is a 16MB or something like that limit in android for VMs, but this program hardly allocates takes up 2MB in RAM (and settings->Apps shows I have another 650 MB spare ram left).
Any idea what might be causing this crash? And how to fix it?
regards
The allocation you’re doing actually isn’t static. If
Xis a local variable inside a function it will be dynamically allocated on the stack (which typically is much smaller than the heap) each time the function is entered, and freed when the function returns.If you really meant for
Xto be static (i.e. there should be one copy ofXshared across all instances of the thread function) you could declare the variablestatic.If you meant for each thread to have its own copy of X you should explictly allocate space on the heap using
malloc() / new []and free it withfree() / delete [].