Skip to content

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

Open
@gopi487krishna

Description

@gopi487krishna

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions