Heap & Stack

Source: Internet
Author: User

Data Structure
1. Heap: FIFO (Fifo-first in First out)
2, Stack: Advanced Back (Filo-first in the last out)

C + +
The memory consumed by a compiled program is divided into the following sections:
1. Stack (stack)-Automatically allocated by the compiler to release, the name of the parameter that holds the function, the name of the local variable, and so on. It operates in a manner similar to a stack in a data structure.
2. Heap area-allocated by the programmer to release, if the programmer does not release, the end of the program may be recycled by the OS. It is different from the heap in the data structure and is distributed in a similar way to a linked list.
3. Static zone-the storage of global variables and local static variables is placed in one piece. Released by the system after the program is finished.
4, literal constant area-the constant string is placed here, the program is released after the end of the system.
5. Program code area-binary code that holds the function body.

Java
1. Stack (stack) and heap are the places that Java uses to store data in RAM. Unlike C + +, Java automatically manages stacks and heaps, and programmers cannot directly set up stacks or heaps.
2, the advantage of the stack is that the access speed is faster than the heap, second only to the register directly in the CPU. However, the disadvantage is that the size and lifetime of the data in the stack must be deterministic and inflexible. In addition, stack data can not be shared between multiple threads or multiple stacks, but multiple variables with equal values within the stack can point to an address. The advantage of the heap is that the memory size can be allocated dynamically, and the lifetime does not have to tell the compiler beforehand that the Java garbage collector automatically collects the data that is no longer in use. However, the disadvantage is that the access speed is slower due to the dynamic allocation of memory at run time.

Heap & Stack

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.