#include <iostream>
#include <utility>
int main()
{
double* ptr;
{
double temp = 5.5;
ptr = new double(std::move(temp));
} // temp dies here
std::cout << *ptr << "\n";
delete ptr;
}
I know this works. But my point is whether this "5.5" rvalue is gonna be directly transferred to the same but dynamically allocated address? That is, does ptr
still point to temp
even when temp
is no longer in scope?
Let's say it is a huge array we want to move from short-term local range to longer-term storage and later we decide when the variable dies.
More explanations:
Suppose we have address A located in memory. It is going to die in a while but before it dies we are making a cool trick and lock this same A address so that it will not die. Thus we did not have to copy stuff to keep it alive. We just locked it. Is that possible in c++?