使用 C 语言的简单引用计数器的示例代码或项目

发布于 2024-08-05 02:51:43 字数 61 浏览 9 评论 0原文

我想知道集成引用计数(或其他托管内存)机制来管理 C 中的一些结构库会有多困难。您会建议我查看哪些示例代码?

I am wondering how difficult it would be to integrate a reference counting (or other managed memory) regime for managing some of my struct libraries in C. What sample code would you recommend I look at?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

做个少女永远怀春 2024-08-12 02:51:43

这个垃圾收集器广泛用于C(甚至在gcc中)

This garbage collector is widely used for C (even in gcc)

書生途 2024-08-12 02:51:43

Python 使用基于 RC 的垃圾收集,它还 解决循环引用问题(即,当您有两个或多个对象相互引用但没有其他对象时)引用它们;在这种情况下,引用计数将> 0,但可以收集整个周期)。

Python uses garbage collection based on RC and it also solves the circular reference problem (i.e. when you have two or more objects that reference each other but no one else references them; in this case, the ref count will be > 0 but the whole cycle could be collected).

哥,最终变帅啦 2024-08-12 02:51:43

XMLRPC-cjson-c 是使用引用计数的 C 库的示例(并且对于何时在幕后增加它们的方法略有不同)。如果您处于多线程环境中,您可能还会对 kref 在 Linux 内核中的用法。

XMLRPC-c and json-c are examples of C libraries that use reference counting (and have slightly different approaches as to when to increment them behind the scenes) . If you are in a multi-threaded environment, you might also be interested in the kref usage in the Linux kernel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文