Java Memory Usage
来源:互联网 发布:必向东java 编辑:程序博客网 时间:2024/05/20 03:07
eg:
1.5.4The correct answer is: 944public class MysteryBox { // 16 (object overhead) private long x0; // 8 (1 long) private double y0, y1; // 16 (2 double) private boolean z0, z1; // 2 (2 boolean) private int[] a = new int[216]; // 8 (reference to array) // 888 (int array of size 216) ... 6 (padding to round up to a multiple of 8)} ---- 944
(The explanation below is copied from http://algs4.cs.princeton.edu/11model/)
Memory usage.
To estimate how much memory our program uses, we can count up the number of variables and weight them by the number of bytes according to their type. For a typical 64-bit machine,- Primitive types. the following table gives the memory requirements for primitive types.
- Objects. To determine the memory usage of an object, we add the amount of memory used by each instance variable to the overhead associated with each object, typically 16 bytes. Moreover, the memory usage is typically padded to be a multiple of 8 bytes (on a 64-bit machine).
- References. A reference to an object typically is a memory address and thus uses 8 bytes of memory (on a 64-bit machine).
- Linked lists. A nested non-static (inner) class such as our Node class requires an extra 8 bytes of overhead (for a reference to the enclosing instance).
- Arrays. Arrays in Java are implemented as objects, typically with extra overhead for the length. An array of primitive-type values typically requires 24 bytes of header information (16 bytes of object overhead, 4 bytes for the length, and 4 bytes of padding) plus the memory needed to store the values.
- Strings. A String of length N typically uses 40 bytes (for the String object) plus 24 + 2N bytes (for the array that contains the characters) for a total of 64 + 2N bytes.
Beginning with Oracle and OpenJDK Java 7, Update 6, the representation of the string data type has changed. See this article for more details.
0 0
- Java Memory Usage
- Memory usage of Java objects: general guide
- Typical memory usage for objects in java
- More on Memory Usage
- Memory usage by user
- View memory usage
- Havok Optimizing memory usage
- Android Memory Usage
- Android Memory Usage
- Linux Memory Usage: free
- android profile memory usage
- Android memory usage
- Virtual Memory Usage from Java under Linux, too much memory used
- Virtual Memory Usage from Java under Linux, too much memory used
- Code Optimization: Effective Memory Usage
- Usage simple of shared memory
- Understanding memory usage on Linux
- Evaluating Memory and Cache Usage
- Gradle 进行 Android 多渠道多包名换图片全自动打包
- 百度地图API--百度地图底色选择
- zoj 3810
- Linux MySQL操作
- Struts2中过滤器,拦截器,监听器他们之间有什么区...
- Java Memory Usage
- extjs Combobox动态加载数据问题,mode:local 还是remote
- 库函数学习(1):简单实现strcpy
- Angularjs 第五章 读书笔记
- 1159 Palindrome(最少插入回文串)
- Web项目管理工具精选
- VC++ 安装驱动 详细解释
- SQL Server中的Collate排序规则关键字的使用
- Java compiler level does not match the version of the installed Java 及MyEclipse中没有ProjectFacets