Android的&放大器;的Dalvik - 获取一个对象的大小放大器、大小、对象、Android

2023-09-04 06:20:55 作者:背影成伤

大家都知道Java 5引入获取对象轻松大小的能力仪表。有没有在Android和的Dalvik这样的方法?

As we all know Java 5 introduced the ability for Instrumentation to get the size of an object with ease. Is there such a method on Android and Dalvik?

的java.lang.instrument 包不能在Android上。

The java.lang.instrument package is not available on Android.

推荐答案

有关它的价值,我已经看过了Dalvik虚拟机源$ C ​​$ C并不能找到任何稳定的API来获取对象的大小。如果你想看看自己,物体的大小存储在 ClassObject :: objectSize:为size_t ,见的Dalvik / VM / OO / Object.h

For what it's worth, I have looked at the Dalvik VM source code and can not find any stable API to get the size of an Object. If you want to take a look yourself, the size of an object is stored in ClassObject::objectSize : size_t, see dalvik/vm/oo/Object.h.

有,然而,内部的API获取一个对象的大小。它用于由DDMS报告关于对象的尺寸的详细信息。但是,由于API是内部的,它很可能不同版本的Andr​​oid之间发生变化。此外,该API是围绕将生字节[] 的数据,并基于客户端/服务器,而不是一个简单的库调用,所以这将是非常尴尬的使用。如果你想看看,在 dvmAllocObject启动()在的Dalvik / VM /分配/ Alloc.cpp 和 dvmTrackAllocation()电话。

There is, however, internal APIs to get the size of an Object. It is used by DDMS to report detailed information about object sizes. But, since the API is internal, it is likely to change between different versions of Android. Plus, the API is sends raw byte[] data around, and is client/server based and not a simple library call, so it will be extremely awkward to use. If you want to take a look, start in dvmAllocObject() in dalvik/vm/alloc/Alloc.cpp and the dvmTrackAllocation() call.

要总结一句话:有不幸的是没有任何可使用的,稳定的API,以获取在Dalvik虚拟机的对象的大小。

To sum it up: there is unfortunately not any readily usable, stable API to get the size of an Object in the Dalvik VM.