Classification of storage areas of Javase

Source: Internet
Author: User

Java Storage Area

Register (Register):

The register is not the same as other stores, it is located in the CPU, is the fastest access to the storage area, but due to the limited number of registers, its allocation by the CPU on demand, programmers do not need to allocate, and can not let the programmer to allocate.

Stacks (Stack):

Located in RAM and operated by a stack pointer (stack pointer) directly supported by the CPU, the SP allocates new storage space by moving down (sp+1), moving Up (sp-1) to free up storage space. It is a quick way to allocate storage space after registers. During the creation of the program, the Java compiler must know the exact size and lifecycle of all data on the stack, so that it can generate stack pointers to move up and down allocations to free up storage space. But this also limits the flexibility of the code. When some Java stores are on the stack--the object's reference, and the Java object itself is not stored on the stack (Java objects are stored in the heap).

Heaps (heap)

In RAM, the memory pool in which Java objects are stored, compared to stacks, the Java compiler does not have to know how much storage space the heap allocates and how long its life cycle is. Therefore, allocating storage space on the heap is more flexible and convenient, whenever you want to allocate storage space, just use the new keyword, and when this code is executed, it allocates storage space on the heap. This gives you the flexibility to increase the cost of time.

Static storage area (static storage):

Static represents a fixed storage area, and in RAM, static storage includes data that is valid throughout the run. You can use static to specify that special objects are static. But the Java object itself is not static.

Constant Store (constant storage):

Constants are usually placed directly in the code of the program. This is safe, because they can never be changed. At some point multiple constants can be separated by themselves, so that the embedded system may be arbitrarily placed in the read-only memory (ROM).

Non-RAM storage area (Non-ram storage):

If the data exists entirely outside of the program, the data can exist without the program's control when the program is not running. For such cases, there are two main examples to illustrate: First, object flow (streamed objects), which is usually sent to other machines in the form of a byte stream. Two, persisted object (Persistent objects), this object is stored on disk, even if the program is aborted, they remain in the original state. These memories are stored in some form in other media, Then restore it to a regular ram-based object when needed. Java provides support for lightweight persistence. In the future Java release, Java will provide more complete support for persistence.

Classification of storage areas of Javase

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.