是否可以使用Boehm垃圾收集器只为程序的一部分? [英] Is it possible to use Boehm garbage collector only for the part of the program?

查看:300
本文介绍了是否可以使用Boehm垃圾收集器只为程序的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读了 LinuxJournal中的文章 www.hpl.hp.com/personal/Hans_Boehm/gc/\"> Boehm-Demers-Weiser垃圾收集器库。我有兴趣在我的库中使用它,而不是我自己的引用计数实现。

I've read article in LinuxJournal about Boehm-Demers-Weiser garbage collector library. I'm interesting to use it in my library instead of my own reference counting implementation.

我只有一个问题:是否可以只使用gc作为我的共享库,并在主应用程序中仍然使用malloc / free?我不太明白gc如何检查堆,所以我担心gc的性能和可能的副作用。

I have only one question: is it possible to use gc only for my shared library and still use malloc/free in the main application? I'm not quite understand how gc checks the heap so I'm worrying about performance of gc in that case and possible side effects.

推荐答案

example 在手册中指出:


使用系统 malloc - 免费收集分配。如果你这样做,你需要小心不要将指向垃圾回收堆的指针存储在用系统 malloc 分配的内存中。

It is usually best not to mix garbage-collected allocation with the system malloc-free. If you do, you need to be careful not to store pointers to the garbage-collected heap in memory allocated with the system malloc.

更具体地说,对于C ++:

And more specifically for C++:


在C ++的情况下,特别注意不要在没有被收集器跟踪的区域中存储指向垃圾收集堆的指针。收集器包括一些备用界面,以便更轻松。 p>

In the case of C++, you need to be especially careful not to store pointers to the garbage-collected heap in areas that are not traced by the collector. The collector includes some alternate interfaces to make that easier.

查看手册中的源代码,您将看到通过特定调用处理垃圾回收的内存,因此,管理单独处理(由收集器或手动)。所以,只要你的库正确处理它的内部,并且不公开收集的内存,你应该很好。你不知道其他图书馆如何管理他们的记忆,你可以使用它们,不是吗? :)

Looking at the source code in the manual you will see the garbage-collected memory is handled through specific calls, hence, the management is handled separately (either by the collector or manually). So as long your library handles its internals properly and doesn't expose collected memory, you should be fine. You don't know how other libraries manage their memory and you can use them as well, don't you? :)

这篇关于是否可以使用Boehm垃圾收集器只为程序的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆