Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

References get invalidated on insertion of a new HDU by the user #162

Open
gopi487krishna opened this issue Sep 9, 2020 · 0 comments
Open

Comments

@gopi487krishna
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant