Where is the program saved?

Source: Internet
Author: User

When the program is running, we'd better have a good idea of where to keep the data. Special attention is paid to the allocation of memory. There are six places to save data:
(1) registers. This is the fastest save area because it is located in a different place from all other ways of saving: inside the processor. However, the number of registers is very limited, so registers are assigned to the compiler as needed. We have no direct control over this and it is impossible to find any traces of registers in our own programs.
(2) stack. resides in the regular RAM (random access storage) area, but can receive direct support for processing through its stack pointers. If the stack pointer moves downward, the new memory is created, and if you move up, the memory is freed. This is a particularly fast, particularly effective way to save data, second only to registers. When you create a program, the Java compiler must accurately know the "length" and "presence time" of all the data stored in the stack. This is because it must generate the appropriate code to move the pointer up and down. This restriction undoubtedly affects the flexibility of the program, so although some Java data is stored on the stack-especially the object handle-the Java object is not placed in it.
(3) heap. A general-purpose memory pool (also in a Ram area) in which Java objects are saved. Unlike stacks, the most intriguing aspect of the memory heap or heap is that the compiler does not have to know how much storage to allocate from the heap or how long the stored data will stay in the heap. Heap Therefore, there is greater flexibility in saving data with a heap. When you want to create an object, you only need to use the new command to compile the relevant code. When you execute this code, the data is saved automatically in the heap. Of course, to achieve this flexibility is bound to pay a certain price: in the heap allocation of storage space will take a longer time!
(4) Static storage. The "static" here means "in a fixed position" (although it is also in RAM). Statically stored data is ready to be invoked while the program is running. Use the static keyword to indicate that a specific element of an object is static. However, the Java object itself will never be placed in the static storage space.
(5) Constant storage. Constant values are usually placed directly inside the program code. It is safe to do so because they will never change. Some constants need to be strictly protected, so consider placing them in read-only memory (ROM).
(6) Non-RAM storage. If the data is completely independent of a program, the program can still exist when it is not running and is outside the control of the program. The two most important examples are "streaming objects" and "fixed objects". For streaming objects, the object becomes a byte stream, which is usually sent to another machine. For fixed objects, the object is saved on disk. Even if the program aborts, they can still keep their state unchanged. A particularly useful technique for these types of data storage is that they can exist in other media. Once needed, they can even be restored to normal, ram-based objects. Java 1.1 provides support for lightweight persistence. The future version may even provide a more complete solution.

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.