Introduction to the types of buckets in Java

Source: Internet
Author: User

In thinking in Java, six Storage types of Java are listed.
1. Register

Those who have compiled assembler programs should be very familiar with registers. At that time, ax, BX, CX, Dx and so on should be used. Registers are in the CPU, so the speed is very fast, but the number is very limited. In Java, you cannot directly deal with registers, but in C, you can declare register variables.
2. Stack space

I certainly feel very cordial when I have written the Assembly. Isn't it just the pressure stack and the out stack in the assembly program? There is a pointer control stack space. The allocated space is the stack pointer moving up, that is, the push operation, and the release space pointer moving down, that is, the pop operation. Of course, C and C ++ mainly allocate space through stacks. As long as the stack is pressed and the outbound stack is pressed, the speed is extremely fast. In Java, object references are allocated through stacks, but Java objects are not allocated through stacks. This is also the reason why Java is relatively inefficient. There is a limit for allocating space through stacks, that is, the size of the space must be determined during compilation, that is, the runtime memory should be known before the program runs. For example, the number of bytes occupied by mov ax and 4 is determined during compilation.
3. Heap Space

It is a large memory block, which is applied for allocation when needed. The objects in Java are not matched in the heap. However, the collection of heap space is troublesome, so the collection algorithms of JVM are complicated. However, if the heap space is large, that is, the memory is not used up, the JVM generally does not start the garbage collector. In this case, the heap efficiency is similar to that of the stack, but the heap has no space to recycle. If you want to start GC from time to time, the efficiency may be extremely low.
4. static storage Zone

Variables declared as static are stored in a static storage zone because they exist all the time (throughout the program.
5. Constant storage Zone

Declared as final static is a constant, which can be stored in the constant storage area, and the string type objects are all constants. The system maintains a String constant pool.
6. other storage

Non-RAM memory, mainly tape and disk.
The most important thing here is the stack and heap. The stack should be the most widely used. In assembly, function calls are generally like this:
1. Pressure stack (protecting the site)
2. Go to method call
3. Outbound stack (recovery site)
Here is a simple description. The above process may have a lot of nesting, but the general process is like this. It is also true in other languages.

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.