Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java objects are taking up much space     - CentOS 6 Install Linux kernel source (Linux)

- php performance monitoring module XHProf (Linux)

- CentOS 6 adds disk quota limit (Linux)

- Btrfs file system creation and their characteristics in Linux (Linux)

- How to upgrade to Ubuntu 14.04 Ubuntu 14.10 (Linux)

- Linux for enterprises to build a firewall (Linux)

- Configuring ftp server and nfs server under Linux (Server)

- Tab set to four spaces in Vim (Linux)

- MySQL log from the library than the main library (Database)

- Linux file and directory permissions settings (Linux)

- When a software RAID data recovery and reconstruction of how failure (Linux)

- Inxi: Get Linux system and hardware information (Linux)

- Oracle create a temporary table space group (Database)

- Chromium Install Flash Official Guide (Linux)

- MySQL 5.5 on master-slave copy filter (Database)

- To use Linux to create a secure managed gateway (Linux)

- Linux installed PCRE (Linux)

- Package the Python script file into an executable file (Programming)

- RHEL5 / 6 Installation Notes (Linux)

- Zabbix monitoring tool deployment under Ubuntu server (Server)

 
         
  Java objects are taking up much space
     
  Add Date : 2018-11-21      
         
       
         
  No sizeof operator in Java, so there is no way of knowing an object in the end take up much space, but in the assignment when there will be some basic rules, we can roughly judge them according to these rules size of the object.

Object header

Head object at least two WORD, if it is an array, then three WORD, which reads as follows:

HashCode, lock information object
A pointer to the object type data
Length of the array (if it is an array of words)
rule

First, any object that is 8-byte aligned, according to property [long, double], [int, float], [char, short], [byte, boolean], the order of reference is stored, for example:

publicclassTest {byte a; int b; boolean c; long d; Object e;}
If the properties of an object in the order of storage, then, to take up space for: head (8) + a (1) + padding (3) + b (4) + c (1) + padding (7) + d (8) + e (4) + padding (4) = 40. However, according to the rules are: head (8) + d (8) + b (4) + a (1) + c (1) + padding (2) + e (4) + padding (4) = 32. I can see saving a lot of space.

When it comes to inheritance is a basic rule: first store in the parent class member, then the child is a member of the class, for example:

class A {long a; int b; int c;} class B extends A {long d;}
Such storage space and order as follows: head (8) + a (8) + b (4) + c (4) + d (8) = 32. But if the parent class attributes eight bytes is not enough how to do? So there is a new rule: the parent class interval with the last member of the first member of a subclass if not four bytes, then the need to extend the basic unit of four bytes, for example:

class A {byte a;} class B extends A {byte b;}
Then the time occupied space as follows: head (8) + a (1) + padding (3) + b (1) + padding (3) = 16. Obviously, this way more waste of space, so there: If the first member of the subclass is double or long, and the parent does not run out of 8 bytes, JVM will destroy the regulation will be filled to the smaller data space, for example:

class A {byte a;} class B extends A {long b; short c; byte d;}
In this case the space occupied as follows: head (8) + a (1) + padding (3) + c (2) + d (1) + padding (1) + b (8) = 24.
     
         
       
         
  More:      
 
- Ubuntu install Eclipse for C / C ++ and related configuration (Linux)
- How to upgrade Docker 1.6 on Fedora / CentOS (Server)
- CentOS 7 repair MBR and GRUB (Linux)
- Ubuntu 12.04 installed OpenCV 2.3.1, binary image (Linux)
- Linux screen command (Linux)
- MyEclipse configuration necessary (Linux)
- HomeKit Human Interface Guidelines (Linux)
- Android in the coordinate system and a method to obtain the coordinates (Programming)
- MySQL 5.6 master-slave replication configuration (Database)
- systemd run levels and service management command Introduction (Linux)
- 20 open source / commercial Linux server management control panel (Server)
- CentOS 6 Install Xen4.2 Virtualization Practice (Linux)
- stat Usage: Get permission to file the corresponding figures (Linux)
- MySQL can not write the data keyword conflicts (Database)
- Python Django model within the class meta Detailed (Programming)
- Vim useful plugin: YouCompleteMe (Linux)
- Vi (Vim) keyboard map and its basic commands (Linux)
- Oracle 11g RAC installation considerations Miscellany (Database)
- Learning UNIX good habits (Linux)
- Ubuntu 14.04.1 LTS compile and install the new kernel (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.