简体   繁体   中英

Is their a guaranteed lifetime for file-scope variables declared in .c and .cpp files (JNI)?

When calling JNI functions from Java in an Android app using JNI, is their a guaranteed lifetime for variables declared at file-scope? We call this function a few times, can the Android system unload our program from memory without terminating the app's process in order to conserve memory in between calls? Is our variable lifetime guaranteed for the life of the process?

#include <stuff>

int counter = 0;

extern "C" void com_package_Class_dostuffFromJava(JNIenv.....)
{
    LOG("Counter: %d" , counter);
    ++counter;
}

Any operating system can swap or page memory, but I don't see why it concerns you. The 'guaranteed life' of a file-scoped variable in C is the life of the process.

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