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

Deferred object destruction for shared_ptr #111

Open
ohhmm opened this issue Mar 1, 2024 · 1 comment
Open

Deferred object destruction for shared_ptr #111

ohhmm opened this issue Mar 1, 2024 · 1 comment

Comments

@ohhmm
Copy link

ohhmm commented Mar 1, 2024

Once during profiling, I noticed that deletion has major performance impact.
Since I don't rely on object under shared_ptr destruction end, I decided to defer the destruction to increase overall performance of getting results.
My solution looks like this: void DispatchDispose(std::shared_ptr<void>&&);: https://github.com/ohhmm/openmind/blob/d2a58112b8e341e8733466e9710feb2ce11d882d/omnn/rt/GC.h#L19

My thought was about that in fact hardly anyone rely on last shared_ptr deletion end to continue code execution. Its only goal is to cleanup resource, but it does not matter when.

I guess that may be useful to have resource cleanup governors for shared_ptr or new kind of smart pointers for this.

@pdimov
Copy link
Member

pdimov commented Mar 1, 2024

If you control how the shared pointers are created, you can use a "deferred deleter" for this, e.g.

https://www.boost.org/doc/libs/1_84_0/libs/smart_ptr/doc/html/smart_ptr.html#techniques_delayed_deallocation

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

2 participants