K
K
kirillleogky2020-09-08 11:56:30
Data Structures
kirillleogky, 2020-09-08 11:56:30

What is Heap (heap)?

Tell me what a heap is in js
Heap (heap) - objects are collected in a heap, which is nothing more than a name for the least structured part of memory.
I don't get the gist of this definition.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2020-09-08
@kirillleogky

There are 2 areas of memory - heap and stack. A heap is just memory from which you can allocate some bytes for your objects. Where they will be in a heap you cannot know in advance. The stack is used for function calls, parameter passing, and for local variables. On the stack, bytes cannot be allocated from the middle - bytes are always allocated from one end and only the last (last allocated) area can be freed. A stack is like a dead end railroad. You can drive new cars there and remove them from there, but only from the end.
It should be clear here that the stack has some kind of structure, and the heap has no structure - therefore it is an "unstructured" memory area.

A
Anton Shamanov, 2020-09-08
@SilenceOfWinter

Heaps are tree structures that follow the properties of a heap: each node is greater than or equal to its children, using an embedded comparison method that is common to the entire heap for comparison.
those. we add elements to the heap in a different order, and as a result, the same increasing "heap" is formed
1
         |
+-----+--+--+-----+
|     |     |     |
2     3     4     5
|     |           |
+   +-+-+         +
|   |   |         |
7   6   8         9
                  |
                +-+-+
                |   |
               10   11

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question