The storage area is divided into 6 categories in Java. The register, stack, stack, static storage, constant storage, and non-random access storage area, respectively, and non-random access storage area (non-Ram). 1. Register. The register is different from the other store, which is located in the CPU, so it is the fastest storage area of the access speed. However, since the number of registers in the CPU is very limited, the use of registers is The CPU is assigned on demand. We don't have to directly control it when programming. And there is no way to find the basis for the use of registers in the program.
2. Stack. It is located in the Random Access Memory (RAM) and operates by a stack pointer directly supported by the CPU. Stack pointer allocates new storage space by moving downwards, and passing Move up to release the storage space. This is only the way the storage space is effectively allocated only to the register. During the creation program, the Java compiler must know the exact size of all the data stored on the stack and their lives. The cycle. This can generate a code to allow the stack pointer to move up and down. But this constraint limits the flexibility of the code, so when some Java storage area is on the stack - especially, object reference (Object Reference) - The Java object itself is not stored on the stack.
3. Heap. This is a memory pool that stores all objects of Java (also in the RAM area). The advantage of the heap is that it is not like a stack, the compiler does not need to know how much storage it should be allocated from the heap. Space, or storage space should have a lot of stacks. Therefore, how much storage space is allocated on the heap. No matter when you need to create an object, you only need to use the keyword New in your code. Create it. In this code, the corresponding storage space is assigned on the heap (HEAP). Of course, it also needs to pay a certain price for such flexibility: allocating storage spaces on the stack than in the stack When the storage space is more time (if you can create an object on the STACK if you can in Java, create an object on the Stack).
4. Static storage. "Static" is "in a fixed location" (although it is also in the RAM). Static storage area includes: data for the entire run of the program You can use the keyword stat to specify a special object is static. But the Java object itself never placed in a static storage area.
5. Constant Storage (constant storage). Constant is usually placed directly in program code. This is safe because they can never be changed. At some time, multiple constants can be separated from themselves, so in embedded systems It can be placed in a read-only memory (ROM) in any place.
6. Non-Ram Storage. If the data is completely existing in the program, the data can be existed when the program is not runtably, and is not controlled. For this type, there are two main Example to explain: 1. STREAMED Objects, which is usually sent to other machines in the form of word streams. Second, persistent objects, this object is stored on disk, even They still maintain the original state after procedure. These memories are saved in some form in some form, and then restore it to regular RAM-based objects when needed. Java provides light Square permanent support. In future Java versions, Java will provide more complete persistence support.