垃圾收集问题 [英] garbage collection questions

查看:67
本文介绍了垃圾收集问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试为C / C ++实现垃圾收集,主要是为了学习b
学习目的。我不知道从哪里开始。


例如 -

基本问题 - 如何识别包含指针的变量

?我在哪里查找这些变量以及如何判断分配给它们的是什么
是指针?


我是否需要实现自己的API malloc / free(或new / delete)或

我可以创建一个可以与给定源代码链接的库
使用标准malloc的
吗?

方法是否有任何权衡?


感谢任何指向网络或教科书等信息的指示。


TIA

解决方案
vk02720写道:

我正在尝试为C / C ++实现垃圾收集,主要用于学习目的。我不知道从哪里开始。

例如 -
基本问题 - 如何识别包含指针的变量
?我在哪里查找这些变量以及如何判断分配给它们的是什么指针?

我是否需要为malloc / free(或new / delete)实现自己的API )或者
我可以创建一个可以与给定源代码链接的库吗?使用标准的malloc?是否有任何
任何折衷的方法吗?

感谢任何指针在网页或文本书籍等任何信息

TIA


您肯定需要注意这一点:

http://www.hpl.hp.com/personal/Hans_Boehm/gc/

vk02720写:

我正在尝试为C / C ++实现垃圾收集,主要用于学习目的。我不知道从哪里开始。


不要劝阻你,但这是一个充满野心的项目。我谦卑地说,如果你不知道从哪里开始,你可能会咬你的b
比你有合理的机会可以获得更多

来咀嚼。

例如 -
基本问题 - 如何识别包含指针的变量
?我在哪里查找这些变量以及如何判断分配给它们的是什么指针?

我是否需要为malloc / free(或new / delete)实现自己的API )或者
我可以创建一个可以与给定源代码链接的库吗?使用标准的malloc?
方法有任何权衡吗?


垃圾收集不能简单地粘贴到标准内存上。

型号。记忆的内容没有任何内容告诉你谁引用了它。诸如分析器之类的工具可以对这种类型进行一些分析,但是在性能测试之外会有一些不可接受的开销



因此,开始的地方是了解标准内存模型

如何工作,令人难以忍受的细节,因为你所说的是

剥掉整个东西并取而代之。还是听起来很有趣

项目? (好吧,我会承认,这听起来很有趣,但我仍然认为

听起来你不知道你在做什么)。

欣赏任何指针上的web或文本书籍等任何信息



安德烈Alexandrescu的的"现代C ++设计与QUOT;有一章关于编写一个

自定义分配器。不过我最近看到他发表了一个演讲,他现在不赞成采用基于政策的设计的方法。当然,这仍然是有益的。然而,我开始的第一个地方是通过

Stroustrup读取TC ++ PL(第3版或特别版)中的所有相关材料。

。登记/>

卢克


vk02720写道:

例如 -
基本问题 - 如何识别包含指针的变量
?我在哪里查找这些变量以及如何判断分配给它们的是指针?


您可以做的是,提供函数,以便类实现者能够向成员注册指向
的指针。还提供了一个虚拟基类来

注册对象本身。

我是否需要为malloc / free(或new / delete)或
我可以创建一个可以与使用标准malloc的给定源代码链接的库吗?
方法有任何权衡吗?


你可以,但我怀疑你必须...如果你正在进行堆压缩,那么是。

感谢网上任何信息的任何指示或教科书等。

TIA




Ben


Hi,

I am trying to implement garbage collection for C/C++ mainly for
learning purpose. I dont know where to start.

For example -
Basic questions - How do I identify the variables that contain pointers
? Where do I look for these variables and how to tell if what is
assigned to them is a pointer ?

Do I need to implement my own API for malloc/free ( or new/delete ) or
can I create a library that can be linked with the given source code
that uses the standard malloc ? Are there any tradeoffs for either
approach ?

Appreciate any pointers to any info on the web or text books etc.

TIA

解决方案

vk02720 wrote:

Hi,

I am trying to implement garbage collection for C/C++ mainly for
learning purpose. I dont know where to start.

For example -
Basic questions - How do I identify the variables that contain pointers
? Where do I look for these variables and how to tell if what is
assigned to them is a pointer ?

Do I need to implement my own API for malloc/free ( or new/delete ) or
can I create a library that can be linked with the given source code
that uses the standard malloc ? Are there any tradeoffs for either
approach ?

Appreciate any pointers to any info on the web or text books etc.

TIA



You definitely need to be aware of this:

http://www.hpl.hp.com/personal/Hans_Boehm/gc/


vk02720 wrote:

I am trying to implement garbage collection for C/C++ mainly for
learning purpose. I dont know where to start.
Not to discourage you, but that''s a plenty ambitious project. I humbly
suggest that if you have no idea where to start, your probably biting
off significantly more than you have a reasonable chance of being able
to chew.
For example -
Basic questions - How do I identify the variables that contain pointers
? Where do I look for these variables and how to tell if what is
assigned to them is a pointer ?

Do I need to implement my own API for malloc/free ( or new/delete ) or
can I create a library that can be linked with the given source code
that uses the standard malloc ? Are there any tradeoffs for either
approach ?
Garbage collection cannot simply be glued on to the standard memory
model. There''s nothing about the contents of the memory which tells
you who''s referencing it. A tool such as a profiler can do some
analysis of this sort, but with an overhead that would be unacceptable
outside of performance testing.

So, the place to start is to understand how the standard memory model
works, in excruciating detail, because what you''re talking about is
stripping the whole thing out and replacing it. Still sound like a fun
project? (Okay, I''ll confess, it sounds very fun, but I still think
you sound like you don''t know what you''re in for).
Appreciate any pointers to any info on the web or text books etc.



Andrei Alexandrescu''s "Modern C++ Design" has a chapter on writing a
custom allocator. I saw him give a talk recently, though, and he now
disfavors the approach therein in favor of a policy-based design. It''s
still instructive, of course. However, the first place I''d start is by
reading all of the relevant material in TC++PL (3rd or Special Ed.) by
Stroustrup.

Luke


vk02720 wrote:

Hi,

I am trying to implement garbage collection for C/C++ mainly for
learning purpose. I dont know where to start.

For example -
Basic questions - How do I identify the variables that contain pointers
? Where do I look for these variables and how to tell if what is
assigned to them is a pointer ?
What you can do is, provide functions so that the class implementer can
register the pointers to members. Provide also a virtual base class to
register the object itself.

Do I need to implement my own API for malloc/free ( or new/delete ) or
can I create a library that can be linked with the given source code
that uses the standard malloc ? Are there any tradeoffs for either
approach ?
You can but I doubt you have to...if you are doing heap compacting then yes.

Appreciate any pointers to any info on the web or text books etc.

TIA



Ben


这篇关于垃圾收集问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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