Comparison of object placement arrangement between Java and C + +

Comparison of object placement arrangement between Java and C + +

Summary:

In Java, all objects are stored in the heap (a general memory pool), and object references are stored in the stack. We can compare the string declared directly by string with the string declared by new string using equals() and "= =" to understand the relationship between objects and references and their storage locations.

Stack is a fast and effective method of allocating storage, second only to registers. When creating a program, the Java system must know the exact life cycle of all items stored in the stack in order to move the stack pointer up and down.

The advantage of heap versus stack is that the compiler does not need to know how long the stored data lives in the heap. Therefore, heap is more flexible than stack. The stack in Java can not be simply understood as the stack in the data structure, although their English is stack. The stack in Java is located in general-purpose RAM (random access memory), but direct support can be obtained from the processor through the stack pointer. If the stack pointer moves down, new memory will be allocated; if it moves up, those memory will be released.

See P22 of thinking in Java for specific memory allocation.

In C + +: objects declared with new and malloc keywords are stored in the heap, and malloc keyword also operates on heap memory:

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>