How does a computer โ€œknowโ€ which memory is allocated?

When memory is allocated on a computer, how does it know which bytes are already occupied and cannot be overwritten?

So, if these are some bytes of memory that are not used:

[0|0|0|0]

How does a computer know if they are or not? They can be just an integer equal to zero. Or it could be an empty memory. How is this known?

+4
source share
4 answers

It depends on how the distribution is done, but usually it involves manipulating the data that belongs to the allocation mechanism.

. , , , , - .

- malloc() .. , , : , , , . malloc(), , , . , , , , .


. ( 4 kiB) brk() mmap(). , โ€‹โ€‹, , , .

, . , , , - , , , , , - . , , , , .

+5

, , , , . . , , - - . , .

, , ( ), . - , , . .

0

, , - , , . "0" , .

To tell which parts of the memory are used, you need a structure to talk about it. For example, you can split the memory into pieces and keep track of which pieces are used and which are not.

0
source

There are blocks of memory, they are busy or not busy. The heap has very complex data structures that organize it. But the answer to your question is too broad.

0
source

Source: https://habr.com/ru/post/1533076/


All Articles