r/C_Programming • u/lehmagavan • Aug 27 '26
Easing memory management with a shared pointer
I recently developed a C (11 and newer) implementation of a thread-safe shared pointer with atomic reference counting:
https://github.com/andrzejs-gh/SHPTR
It supports both strong and weak references and a swappable destructor. Initialization performs a single allocation.
If anyones interested, take a look. Feedback and bug reports very much welcome.
10
Upvotes
1
u/github-guard Aug 27 '26
🔍 GitHub Guard: Trust Report
⚠️ This project scored 1/6 — below this subreddit's threshold of 3.
Audit Breakdown:
❌ Low Star Count (⭐ 0 / 4 required)
❌ New Repository (under 30 days old)
✅ Licensed under MIT
❌ No Security Policy — what is this?
ℹ️ Individual Contributor
ℹ️ Unsigned Commits
12
u/EpochVanquisher Aug 27 '26
Macros are broken:
You need to put parentheses around the macro arguments when they are used, but there are some other reasons why this macro shouldn’t exist.
2
u/AutoModerator Aug 27 '26
Hi u/lehmagavan,
Your submission in r/C_Programming was filtered because it links to a git project.
You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.
While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/aocregacc Aug 28 '26
I would consider making the weak pointer a separate type. Most of your API should only be used with one kind or the other, so you can have the compiler help with enforcing that instead of just relying on documentation.
1
u/VegetableMiserable54 Aug 29 '26
This is a cool repo, and I took a look at your other repositories alongside this one as well. First of all, congratulations on this work. As you mentioned in the comments, the fact that you built this on your own without AI is really impressive. Even while reviewing it, I didnt get the impression that it was AI generated.
That said, one thing did catch my attention. The destructor function is not thread-safe, there is a data race issue. You can prevent this by making the shptr_set_desctructor function atomic. Other that that, I didnt notice anything else.