Why are value types created in stack and reference types created on the heap?

Books in programming languages โ€‹โ€‹usually explain that value types are created on the stack, and link types are created on the heap.

My question is why.

+4
source share
2 answers

My question is why.

Why do they "explain" this? Because sometimes authors do not know themselves better, and sometimes they are too lazy to explain it correctly. True, it is quite complicated.

Fortunately, Eric Lippert wrote a lot about this:

While I usually tried to at least include the paraphrase of the complete answer here, I am not going to do this here because explaining it very briefly almost inevitably leads to an erroneous result. Just go and read these blog posts and then everything that Eric wrote. It will take weeks, but you will be glad you did.

+11
source

Why do book authors write like this?

1. They did not read Eric Lippert enough.

2. They may not indicate a C # / Java compiler, and they may think of some other magic language.

3. They (the authors) read the same from some other books (so now in the loop)

4. [IMP] It is very easy to remember (not useful) in 1 lowercase expression, and not in the statements of Eric Lippert.

5. Many programmers (like me) just read; for them, it really doesn't matter what happens in RAM. They want the screen (monitor) to be displayed on the screen. They want to remember these facts (depending on which is simpler and closer to reality) for the interview.

6. Most people in the current software industry are not like Eric Lippert. So even they do not really know. Therefore, remembering the false will be useful.

+1
source

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


All Articles