I work with the "foo" class from an external library that computes and stores large amounts of data. After the calculation is complete, I want to save only the result data array, which is about half the size of "foo". Foo provides a pointer to the result data using a function RawResultsArray()with a type PNSt3__17complexIdEE. So far I have done this:
int N;
complex<double> * results_to_keep;
{
foo myFoo;
myFoo.findResults();
results_to_keep = new complex<double>[N];
for (auto i=0; i<N; i++)
{
results_to_keep[i] = myFoo.RawResultsArray()[i];
}
}
delete [] results_to_keep;
However, I work with limited memory and cannot afford to have an array results_to_keepand a class myFoo. Is there a way to save the length data N*sizeof(complex<double>)in myFoo.RawResultsArray()after leaving the scope in line 14 without temporarily allocating the full array again?
I played unsuccessfully with smart pointers. I think my best attempt is:
std::unique_ptr<complex<double>[]> results_to_keep;
{
foo myFoo;
myFoo.findResults();
std::unique_ptr<complex<double>[]> temp (move(myFoo.RawResultsArray());
results_to_keep = move(temp);
}
results_to_keep.reset();
, results_to_keep , . malloc: *** error for object 0x106000010: pointer being freed was not allocated.
: typeid(myFoo.RawResultsArray()).name() PNSt3__17complexIdEE. Apple LLVM 8.1.