Is accessing data in the heap faster than from the stack?

后端 未结 7 1109
北荒
北荒 2020-11-29 00:12

I know this sounds like a general question and I\'ve seen many similar questions (both here and on the web) but none of them are really like my dilemma.

Say I have t

7条回答
  •  伪装坚强ぢ
    2020-11-29 00:51

    when allocating buffers on stack the optimization scope is not the cost of accessing the memory but rather the elimination of often very expensive dynamic memory allocation on the heap (stack buffer allocation can be considered instantaneous as the stack as a whole is allocated at thread startup).

提交回复
热议问题