How are arrays created and accessed

后端 未结 4 1677
醉话见心
醉话见心 2020-12-12 03:14

I understand(not completely why, though) that instances of primitive types such as int, float are stored on the stack and are not heap allocated. But I am a bit confused abo

4条回答
  •  独厮守ぢ
    2020-12-12 03:43

    Your "understanding" is flawed, basically. Value type values are sometimes stored on the stack - but not when part of an array or any other heap-based object. It's unfortunate that some people choose to make such a blanket statement around value types living on the stack, which then confuses others :(

    Besides, the stack/heap distinction is an implementation detail...

    See my article on memory for some more details, but definitely read Eric Lippert's blog post (linked in the previous paragraph) for more philosophical considerations. (Read his other posts on value types for even more information.)

提交回复
热议问题