Java如何通过内存对象堆分配在Android中工作 [英] How java works in android through memory object heap allocation

查看:101
本文介绍了Java如何通过内存对象堆分配在Android中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 的新手,但是具有 Java 的经验. 在 Java 中,当我们这样做时:

I am new to Android but experienced in Java. In Java when we do this:

MyClass myObj = new MyClass();

它显然会执行以下操作:

It clearly does the following:

  1. 将内存指针myObj插入堆栈
  2. 为堆中类型为MyClass的对象分配新空间
  3. 指定此新空间对myObj
  4. 的引用
  1. Inserts the memory pointer myObj upto the stack
  2. Allocates a new space for object of type MyClass in the heap
  3. Appoints this new space's reference to myObj

但是我对以下问题有些困惑:

But I am a little bit confused about the following questions:

  1. 但是在 Android 中,这是否以相同的方式工作?
  2. Android 是否具有完整的堆栈和堆内存?
  3. Android 是否可以在我的 Java 应用( Android 应用)上使用Java虚拟机(JVM)?
  1. But in Android, does this work in the same way?
  2. Does Android have full stack and heap memories?
  3. Does Android have Java Virtual Machine (JVM) for my Java app (Android app) to work on?

非常感谢!

推荐答案

Android使用自己的Dalvik虚拟机重新实现了Java虚拟机.与基于堆栈的 JVM 不同, Dalvik 是基于寄存器的.您可以在此处看到两者之间的比较:

Android re-implemented the Java Virtual Machine with their own Dalvik Virtual Machine. Unlike the JVM which is stack-based, Dalvik is register based. You can see a comparison between the two here:

http://en.wikipedia.org/wiki/Dalvik_(软件) #性能

是的,Dalvik VM具有与JVM一样的堆-而不是堆栈.它与任何Java 1.6源代码都100%兼容(对1.7的支持正在慢慢出现,并且在Android Studio中提供了初步的支持).因此,在您的3个步骤中:

Yes Dalvik VM has a heap just like the JVM - just not a stack. It is 100% compatible with any Java 1.6 source code (1.7 support is slowly coming, and preliminary support is available in Android Studio). So in your 3 steps:

  1. 将对myObj的引用插入寄存器中
  2. 在堆中为MyClass类型的对象分配一个新空间
  3. 指定此新空间对myObj的引用

这篇关于Java如何通过内存对象堆分配在Android中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆