Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java objects are taking up much space     - Linux / proc directory Comments (Linux)

- About AWR More Description (Database)

- Windows Ubuntu dual system a key Ghost, grub rescue prompt solution (Linux)

- ssh using scp: / directory: Permission denied (Server)

- Linux Defensive / mitigate DDOS attacks (Linux)

- How to run Kali Linux 2.0 in Docker container (Linux)

- Linux Getting Started tutorial: Experience KVM Virtual Machine chapter (Linux)

- Linux dynamic libraries and Guide (Programming)

- How to build Mono 3.4.0 / 3.4.1 on Windows (Linux)

- To teach you a trick to find the real IP address (Linux)

- Java memory-mapped file MappedByteBuffer (Programming)

- DB2 table space is redirected to restore the database combat (Database)

- File sharing and fork function (Programming)

- ORA-4031 error Solution (Database)

- PyCharm new Python file name and the name of the module will import the same problem might arise (Programming)

- nginx.conf Optimization (Server)

- Linux server startup and logon security settings (Linux)

- Sort sql MySQL 5.6 upgrade slow Cause Analysis (Database)

- C ++ thread creates transmission parameters are changed (Programming)

- Number JavaScript type system (Programming)

 
         
  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:      
 
- Mongo-connector integrated MongoD to achieve incremental Solr index (Server)
- VNC configuration detailed analysis under Linux (Linux)
- Use regular expressions to check whether the input box to enter a URL (Programming)
- Confrontation dragged Library - Web front-end encryption slow (Linux)
- Thunderbird 24.4.2 has been released for use with PPA updates (Linux)
- The Java Properties class action (Programming)
- How to install Nginx on FreeBSD 10.2 as an Apache reverse proxy (Server)
- Gentoo: startx problem appears Failed to load module (Linux)
- wget command examples (Linux)
- Linux-du and df command (Linux)
- Java collections series (Programming)
- SolrCloud-5.2.1 cluster deployment and testing (Server)
- What is Java EE (Programming)
- Install Krita 2.8 on Ubuntu 13.10 / 12.04 / 12.10 (Linux)
- Linux fixes fatal error: x264.h: No such file or directo (Linux)
- MySQL 5.6 database code changes (Database)
- Open source backup software installed on Ubuntu Systemback 1.6.201 (Linux)
- Quagga use authentication on strengthening BGP session security (Linux)
- Deploy Apache Spark cluster environment in Ubuntu (Server)
- Bash job control (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.