Stack and heap – dynamic allocation question
Sources usually mention that dynamically created variables are allocated on the heap, while functions’ variables on the stack. Also the ones on the stack cease to exist automatically when e.g. the function which contains the variable exits. If I understand correctly, data fields of class are on the heap.
I do not understand, what is meant by ‘dynamic’? As I see it, when the code is running, anything being created is created dynamically on the fly, be it function variables or objects with variables inside them. I would be glad for simple explanation. Thanks
find second smallest element in Fibonacci Heap
I need to describe an algorithm that finds the second smallest element in a Fibonacci-Heap using the Operations: Insert, ExtractMin, DecreaseKey and GetMin. The last one is an algorithm previously implemented to find and return the smallest element of the heap.
How does a priority_queue maintain a heap on a deque efficiently?
In the C++ STL, priority_queue
(heap) can be used with any underlying container, such as a deque
. How does the implementation stay O(log n)
if deque
s don’t swap an item in index a
with index b
in constant time?
Why is the main memory for object allocation called the ‘heap’?
Has anybody got an idea why the area of main memory where objects are allocated is referred to as the heap. I can understand the rationale for that of the stack LIFO but would like to know what the rationale is for the ‘heap’ name.
Marked nodes in Fibonacci heaps
I don’t understand why Fibonacci heaps have marked nodes (picture).
A node is marked when its child is deleted. Quoting from Wikipedia: “[Keeping degree of each node low] is achieved by the rule that we can cut at most one child of each non-root node. When a second child is cut, the node itself needs to be cut from its parent and becomes the root of a new tree.”
A good C Variable Length Array example [closed]
Closed 9 years ago.
Applications of heapsort [closed]
Closed 8 years ago.
Heap overflow vs stack overflow
So as a general rule to avoid a stack overflow, big objects should be allocated to the heap (correct me if I am wrong). But, since the heap and the stack expand towards each other, wouldn’t this cause heap overflow or alternatively limit the space for the stack and higher the chances of stack overflow?
Is my ‘variable-storing area’ basically a ‘heap’?
I’m planning to implement a simple VM/interpreter kind of thing for a simple language I’m making. The compiler of the language emits mostly stack-oriented instructions to be executed by the VM.
Is the JVM “heap” inside the JVM software, or inside the physical computer?
I wanted to as this question about VMs in general, but focused it to JVM implementations only so this doesn’t get closed as too broad.