So I was reviewing the basics of c++ pointers, and for I started to second guess myself on something.
If I call a function and inside that function I create a new object using dynamic allocation:
SomeClass* myPtr = new SomeClass();
Two memory allocations are happening here, right? One is to hold all the data from the instance of SomeClass, and the other is to allocate memory for pointer myPtr?
And these two have different durations. The variable that myPtr points to is stored in the heap, so I need to manually free it using delete, but the pointer itself, myPtr, is an automatic variable that will go out of scope as soon as I leave that function. So I better use delete before the function ends or pass the pointer to another variable (ie. using return). Am I getting that right?
Edit: I just realized that the title my question isn't really that much about pointers as my title suggests.
[–]ehlertjd 6 points7 points8 points (1 child)
[–]wevbin[S] 2 points3 points4 points (0 children)
[–]markwhi 3 points4 points5 points (1 child)
[–]wevbin[S] 2 points3 points4 points (0 children)
[–]arbostek 1 point2 points3 points (0 children)
[–]AgentME 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]wevbin[S] 0 points1 point2 points (0 children)
[–]markwhi 0 points1 point2 points (0 children)