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

New shared_ptr implementation #5883

Merged
merged 1 commit into from
May 5, 2024
Merged

New shared_ptr implementation #5883

merged 1 commit into from
May 5, 2024

Conversation

vaxerski
Copy link
Member

@vaxerski vaxerski commented May 5, 2024

The reasoning is quite simple - this is a more useful shared_ptr implementation. Whether the impl itself is better - God knows.

I am not sure if this is a great idea either, but:

weak_ptrs got two new superpowers that the stl ones dont have:

  • you can dereference a weak_ptr directly. This will obviously segfault on a nullptr deref if it's expired.
    • this is useful to avoid the .lock() hell where we are 100% sure the pointer should be valid. (and if it isn't, it should throw.)
  • weak_ptrs are still valid while the SP is being destroyed.
    • reasoning: while an object (e.g. CWindow) is being destroyed, its weak_ptr self should be accessible (the sp is still alive, and so is CWindow), but it's not because by stl it's already expired (to prevent resurrection)
    • this impl solves it differently. w_p is expired, but can still be dereferenced and used. Creating s_ps is not possible anymore, though.
    • this is useful in destructors and callbacks.

review pls @outfoxxed @fufexan and everyone else.

TODO:

  • Battle testing.
  • Fix invalid delete

@vaxerski
Copy link
Member Author

vaxerski commented May 5, 2024

should be working. Also ran a quick test for possible leaks, doesn't seem to leak. Needs more testing, though.

@vaxerski vaxerski force-pushed the new-sp branch 6 times, most recently from 190de0e to 98c3a04 Compare May 5, 2024 16:00
@vaxerski vaxerski marked this pull request as ready for review May 5, 2024 16:01
moves std::shared_ptrs to a new implementation
@vaxerski
Copy link
Member Author

vaxerski commented May 5, 2024

thanks, cheers

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

Successfully merging this pull request may close these issues.

2 participants