Description
Adding a new HDU to the list of HDU's by the user results in invalidating the old references held by the user.
Example :
auto& astro_data= fits::open("sample.fits");
auto& ascii_hdu = fits::convert_to<ascii_hdu>(astro_data["TABLE"]);
auto& new_bin_hdu = // Creates a new binary table and stores data in it
astro_data.add(new_bin_hdu);
// After this any operation to ascii_hdu is invalid as the reference has got invalidated
This is happening because in fits_reader.hpp the HDUs are stored inside a vector. If the preallocated buffer is filled up then the vector will expand the size and this expansion involves creating a new buffer copying all the elements. Thus the references created before point to old garbage memory causing the crash.
This problem can be removed by using non contiguous container ( std::list or std::deque )
After looking at the benchmarks here : (https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html)[https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html]
The best candidate would be std::deque. Also references never get invalidated in std::deque and std::deque sometimes performs much better than std::vector