Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java objects are taking up much space     - Ubuntu users how to install the latest Nvidia graphics drivers (Linux)

- shell script: a key optimization CentOS system (Linux)

- Java coding conventions (Programming)

- Use dump restore mode fast backup and recovery system FreeBSD (Linux)

- bash login and welcome message: / etc / issue, / etc / motd (Linux)

- Linux NIC configuration (Linux)

- mydumper installation error process (Database)

- Oracle view object space usage show_space (Database)

- Docker ecosystem security is gradually maturing (Server)

- The Java utility, JavaMail (Programming)

- How to install Perl modules from CPAN (Linux)

- Circular list of Java programming (Programming)

- Swift rewrite initialize method of navigation controller class (Programming)

- Linux Command study manual - GPG command (Linux)

- Puppet 3.5 Source package Installation and Configuration (Server)

- Use NTFS-3G to mount NTFS partitions under Linux U disk and removable hard disk (Linux)

- How to install Wine 1.7.20 under Ubuntu or Linux Mint (Linux)

- Install Oracle 11g illustrations and dependent libraries under SUSE11 (Database)

- Two alert log ORA Errors (Database)

- Linux Nginx FastDFS integration module is installed Nginx and FastDFS (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:      
 
- Cobbler remotely install CentOS system (Linux)
- Java static code analysis tool Infer (Programming)
- Linux Bash share tips for getting started (Linux)
- Ubuntu users to install the system indicator SysPeek 0.3 (Linux)
- Text analysis tools - awk (Linux)
- Java interface (Programming)
- Android Studio Installation and Configuration Guide tutorial (Linux)
- How to set up FTP server on Linux (Server)
- 7 extremely dangerous Linux commands (Linux)
- MySQL related statements (CRUD) (SQLyog software) (Database)
- How ONLYOFFICE collaborative editing document on Linux (Linux)
- Install Redis 2.6 5.5 32 position CentOS error resolved (Linux)
- Android design patterns - state mode (Programming)
- Management Linux Container with Docker in Ubuntu (Linux)
- Linux use logs to troubleshoot (Linux)
- CentOS7 build GlusterFS (Linux)
- CentOS use wget (Linux)
- Security basics: simple analytical framework for Linux system firewall (Linux)
- Android Unzip the ZIP / GZIP data (based on the InflaterInputStream implementation) (Programming)
- Using 30 seconds to write a detailed analysis of garbage removal system (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.