Five kinds of storage position of the object

There are five different places to store data when the program runs

  1. Register.

    This is the fastest storage area, which is located inside the processor. But it's a very limited number, so register allocation Yaoan demand. Not direct human control.

  2. Stack memory.

    It resides in Random Access Memory (RAM),. There can be obtained directly from the processor stack pointer. The stack is moved downward, allocating new memory up

         Mobile is to release that memory. This is an efficient method for allocating memory, only to register. But when you create the Java stack storage system must know all

         Life cycle, it has been up and down to move the pointer. This restricts the flexibility of the program. Therefore, references to Java exist wherein the object, wherein the object not stored.

  3. heap memory.

    It is also located on the RAM, for storing all Java objects. It differs in that the stack and the stack, the compiler need not know the data stored in the life cycle of the heap. therefore

    Heap allocated storage has a lot of flexibility. The disadvantage is that storage allocated on the heap and stack memory and clean up than to spend more time cleaning up.

  4. constants are stored.

    Constant values ​​are usually placed directly inside the Java code, it is safe to do so, because they will never be changed. Sometimes in embedded systems, constant

    And the other part of the separation itself, so in this case, may be stored in a ROM (Read Only Memory).

  5. Non-RAM memory.

    If the data is fully alive to the program outside, then it can not be controlled by any program, it may also be present in the program is not running. Two examples are a stream object

    And persistent objects. In the stream objects, the object is converted into a byte stream. Persistent object store objects on disk. Therefore, even if the program is terminated they can maintain their own

    status.

  Java, data storage is divided into five types. The practical application of the most talked about is the heap and stack. In summary to understand the similarities and differences of the stack.

  

Guess you like

Origin www.cnblogs.com/blue327/p/11082991.html