I have created a C library using Android NDK and created an apk using this prebuild library. This apk calls the foo() function of the library. In this library I have two functions foo() and add(), foo() will call add() using signal(SIGALARM). In C library, there is a memory allocation on the stack (simple declaring an array), if I allocate memory more than 9MB it will crash with sigsegv. You can also suggest an alternative of a signal in C on Unix platform as I want to call this add() function in the background only.
This apk runs fine till nougat. On Oreo and above the background process killed after a certain amount of memory allocation and I have found a workaround on java but I want to do the same on C what should I do please help. I have tried heap memory allocation which runs fine. But I want memory allocation on the stack only, when I allocate stack memory on foreground it runs fine. And how do I push notification using C?
why stack only? Heap, used as shown above in the static example, is just as fast if this is a performance question. The heap is only noticeably slow if you are constantly getting and freeing it, over and over. If its threaded, the static idea is dangerous and you must take care (but a pool of static buffers can do the trick, or mutex locks). What is your real goal here (don't just say "I want it on the stack because I want it on the stack").