Thinking in java--object storage location

Source: Internet
Author: User

1. Register

This is the fastest storage area because it is located inside the processor. However, because the size of the register is limited, the register is allocated by the compiler on demand. You cannot directly control or feel the presence of a register.


2. Stack

is located in general-purpose RAM (random access memory), but can receive direct support from the processor through the "stack pointer". By moving the stack pointer up and down to allocate the required space for the program, its speed is only second to the register speed. When you create a program, the Java compiler must know the exact size and lifecycle of all the data stored in the stack, because it must generate the appropriate code to move the pointer up and down. Such a restriction largely limits the flexibility of the program. So Java, while some of the data is stored on the stack (object references), the actual Java objects are not stored in the stack, but are stored in the heap.


3. Heap

resides in RAM due to storing Java objects. The benefit of a heap that differs from the stack is that the compiler does not need to know the size and life cycle of the space required by the program data. Therefore, the object can be directly new and automatically allocated memory in the heap when executed. This makes the process relatively flexible. But the problem is that allocating a heap for memory allocation takes more time than storing the stack (which is one of the reasons everyone says Java is slow).


4. Static storage

Located in RAM, corresponds to a specific element of an object identified by the static keyword in java. Static refers to: in a fixed position


5. Constant storage

Constant values are usually stored directly inside the program code.


6, non-RAM storage

If the data exists outside the program, it can be free from any control of the program and can exist when the program is not running, corresponding to the "stream object" and "persisted object" in Java.


Thinking in java--object storage location

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.