Where are temporary object stored?

后端 未结 4 1114
一个人的身影
一个人的身影 2020-12-01 12:52

IMO temporary objects are stored in dynamic (heap) memory, but I\'m not sure. Can you please confirm or deny my thoughts?

4条回答
  •  北海茫月
    2020-12-01 13:36

    It depends on their lifetime. Temporaries you create inside of a function that you dont bind to a local static reference to lengthen their lifetime will most likely be created on the stack. Temporaries you bind to local static references will most likely be stored in the .data section of your program binary. Same holds for temporaries you bind to nonlocal references. Temporaries that are created during initialization of a nonlocal variable other that the one bound to by a reference should be on the stack of the function that produces the value of that nonlocal variable.

    Exception objects that represent the thrown object during unwinding are temporaries too. Those usually reside on the heap.

提交回复
热议问题