简体   繁体   English

Android 原生代码栈 vs Dalvik VM / ART 栈

[英]Android Native Code Stack vs Dalvik VM / ART Stack

Android apps can execute C/C++ code using the Android NDK. Android 应用程序可以使用 Android NDK 执行 C/C++ 代码。 All Android apps also run on the Android VM (ie Dalvik/ART).所有 Android 应用程序也运行在 Android VM(即 Dalvik/ART)上。

My question is, does native code in Android apps use the same stack/heap as the Android VM?我的问题是,Android 应用程序中的本机代码是否使用与 Android VM 相同的堆栈/堆?

ie In native code, we can create local variables and also variables via malloc/new, and these will be stored on the stack or heap respectively.即在本机代码中,我们可以通过 malloc/new 创建局部变量和变量,这些变量将分别存储在堆栈或堆中。 But also my understanding is that the Android VM will create objects of it's own for bookkeeping.但我的理解是,Android VM 将创建它自己的对象用于簿记。 So does the native code and Android VM share the same stack/heap in memory?那么本机代码和 Android VM 在内存中共享相同的堆栈/堆吗?

The managed JVM heap and the native heap are separate, but they are not completely isolated.托管 JVM 堆和本机堆是分开的,但并不是完全隔离的。 Under the hood, JVM uses the same system calls, and via JNI, you can access java primitive arrays' memory.在底层,JVM 使用相同的系统调用,并且通过 JNI,您可以访问 Java 原始数组的内存。

As for stack, JVM and C share it per thread.至于堆栈,JVM 和 C 每个线程共享它。 But not all native threads are attached to JVM.但并非所有本机线程都附加到 JVM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM