Where are pointers in C++ stored, on the stack or in the heap? -
Where are pointers in C++ stored, on the stack or in the heap? -
i trying understand difference between stack , heap memory, , this question on this explanation did pretty job explaining basics.
in sec explanation however, came across illustration have specific question, illustration this:
it explained object m
allocated on heap, wondering if total story. according understanding, object indeed allocated on heap new
keyword has been used instantiation.
however, isn't the pointer object m
on same time allocated on stack? otherwise, how object itself, of course of study sitting in heap accessed. sense sake of completeness, should have been mentioned in tutorial, leaving out causes bit of confusion me, hope can clear , tell me right understanding illustration should have 2 statements have say:
1. pointer object m
has been allocated on stack
2. object m
(so info carries, access methods) has been allocated on heap
your understanding may correct, statements wrong:
a pointer object m
has been allocated on stack
m
is the pointer. in stack. perhaps meant pointer member
object
the object m (so info carries, access methods) has been allocated on heap
correct the object pointed m
in created on heap
in general, function/method local object, function parameters created on stack. since m
function local object, on stack, object pointed m on heap
c++ pointers memory-management
Comments
Post a Comment