On the storage space type in Java

Source: Internet
Author: User
Thinking in Java, listing six types of storage in Java
1. Registers
The compiler should be very familiar with the register, at that time with the AX,BX,CX,DX and so on. Registers are in the CPU, so the speed is very fast, but the number is very limited. It is not possible to deal directly with registers in Java, but in c it is possible to declare register variables.

2. Stack space
The compilation is certainly very cordial, in the assembler is not the stack and stack? There is a pointer to control stack space, allocating space is the stack pointer up, that is, push operation, release the space pointer down, is the pop operation. Of course C and C + + also mainly through the stack allocation space. Because as long as the stack and the stack, so the speed is particularly fast. The object references in Java are allocated through stacks, and Java objects are not distributed through stacks, which is why Java efficiency is relatively poor. One limitation of allocating space through stacks is that the size of the space must be determined at compile time, which means that the runtime memory should be known before the program is run. For example, mov ax,4 how many bytes the instruction occupies is determined at compile time.

3. Heap Space
is a large block of memory, when needed to apply for allocation, Java objects in the heap is not matched. But heap space recycling is more cumbersome, so the JVM's recovery algorithm is more complex. But if the heap space is large, that is, the memory is not run out, the JVM generally does not start the garbage collector. In this case the heap efficiency and stack should be similar, but the heap has no recycling space. If you are going to start the GC at any time, you can imagine that the efficiency is extremely low.

4. Static Storage Area
Variables declared as static because they always exist (throughout the program), so they are saved in a static storage area.

5. Constant Storage Area
Constants declared as final static, can be saved in constant storage, and string objects are constants, and the system maintains a string constant pool.

6. Other storage
Non-RAM memory, mainly tapes, disks, and so on.

The most important thing here is stack and heap, the stack should be the most widely used, in the assembly of function calls is generally such a process:
1. Pressure stack (protection site)
2. Enter method call
3. Out stack (restore site)
Here is a simple description, the process may have a lot of nesting, but the general process is this, in other languages is actually the same.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.