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

Fix: use std::visit to replace std::get_if #630

Closed
Light-City opened this issue Jun 4, 2024 · 5 comments
Closed

Fix: use std::visit to replace std::get_if #630

Light-City opened this issue Jun 4, 2024 · 5 comments
Labels

Comments

@Light-City
Copy link

Light-City commented Jun 4, 2024

The destructor of dataset is not well written to release memory. We can use visit to simplify the code.

before:

{
                auto ptr = std::get_if<0>(&x.second);
                if (ptr != nullptr) {
                    delete[] * ptr;
                }
            }
            {
                auto ptr = std::get_if<1>(&x.second);
                if (ptr != nullptr) {
                    delete[] * ptr;
                }
            }
            {
                auto ptr = std::get_if<2>(&x.second);
                if (ptr != nullptr) {
                    delete[] * ptr;
                }
            }
            {
                auto ptr = std::get_if<3>(&x.second);
                if (ptr != nullptr) {
                    if (is_sparse) {
                        delete[](sparse::SparseRow<float>*)(*ptr);
                    } else {
                        delete[](char*)(*ptr);
                    }
                }
            }

after:

for (auto&& x : this->data_) {
            std::visit(
                [](auto&& arg) {
                    using T = std::decay_t<decltype(arg)>;
                    if constexpr (std::is_same_v<T, const float*> || std::is_same_v<T, const size_t*> ||
                                  std::is_same_v<T, const int64_t*>) {
                        delete[] arg;
                    } else if constexpr (std::is_same_v<T, const void*>) {
                        delete[] (char*)(arg);
                    }
                },
                x.second);
Copy link
Contributor

github-actions bot commented Jul 5, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Rotten issues close after 30d of inactivity. Reopen the issue with /reopen.

@github-actions github-actions bot added the stale label Jul 5, 2024
@liliu-z liliu-z removed the stale label Jul 5, 2024
@Light-City
Copy link
Author

/reopen

Copy link
Contributor

github-actions bot commented Aug 5, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Rotten issues close after 30d of inactivity. Reopen the issue with /reopen.

@github-actions github-actions bot added the stale label Aug 5, 2024
@liliu-z liliu-z removed the stale label Aug 7, 2024
Copy link
Contributor

github-actions bot commented Sep 7, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Rotten issues close after 30d of inactivity. Reopen the issue with /reopen.

@github-actions github-actions bot added the stale label Sep 7, 2024
@liliu-z liliu-z removed the stale label Sep 11, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Rotten issues close after 30d of inactivity. Reopen the issue with /reopen.

@github-actions github-actions bot added the stale label Oct 12, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants