+ 4

What is the different between heap and stack

im new learner

10th Nov 2016, 9:09 AM
hakiki
4 ответов
+ 26
stack is used for static memory allocation and heap for dynamic memory allocation, both stored in the computer's RAM. Variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and it's allocation is dealt with when the program is compiled.
10th Nov 2016, 9:56 AM
Nelli
Nelli - avatar
0
i dont think stack is static memory the thing stack is at the time of execution method or function stack memory created and destroyed at the time of method or function execution completed in java heap memory is created dynamically all objects creatwd in heap
21st Nov 2016, 4:03 PM
Ankith Reddy
Ankith Reddy - avatar
0
The stack is the memory set aside as scratch space for a thread of execution. When a function is called, a block is reserved on the top of the stack for local variables and some bookkeeping data. When that function returns, the block becomes unused and can be used the next time a function is called. The stack is always reserved in a LIFO (last in first out) order; the most recently reserved block is always the next block to be freed. This makes it really simple to keep track of the stack; freeing a block from the stack is nothing more than adjusting one pointer. The heap is memory set aside for dynamic allocation. Unlike the stack, there's no enforced pattern to the allocation and deallocation of blocks from the heap; you can allocate a block at any time and free it at any time. This makes it much more complex to keep track of which parts of the heap are allocated or free at any given time; there are many custom heap allocators available to tune heap performance for different usage patterns. Each thread gets a stack, while there's typically only one heap for the application (although it isn't uncommon to have multiple heaps for different types of allocation)
5th Jan 2017, 6:53 AM
User User
- 2
idont know
14th Nov 2016, 7:58 AM
lehlohonolo motsusi
lehlohonolo motsusi - avatar