C ++中的垃圾收集 [英] Garbage collection in C++

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

问题描述

大家好,


C ++中可以进行垃圾收集。它不是

语言支持的一部分。由于

方式设计语言,是否有任何具体原因。或者由于某些特定原因而不鼓励它。如果有人可以提供相同的输入,它将会很有帮助。


问候,

Pushpa

Hi all,

Is garbage collection possible in C++. It doesn''t come as part of
language support. Is there any specific reason for the same due to the
way the language is designed. Or it is discouraged due to
some specific reason. If someone can give inputs on the same, it will
be of great help.

Regards,
Pushpa

推荐答案

< pu ********** @ gmail.comwrote in message

news:22 ** ******************************** @ a29g2000 pra.googlegroups.com ...
<pu**********@gmail.comwrote in message
news:22**********************************@a29g2000 pra.googlegroups.com...

大家好,


C ++中可以进行垃圾收集。
Hi all,

Is garbage collection possible in C++.



当然:

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

Sure:

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


它不是作为

语言支持的一部分。由于

方式设计语言,是否有任何具体原因。或者由于某些特定原因而不鼓励它。如果有人可以提供相同的输入,它将是非常有帮助的。
It doesn''t come as part of
language support. Is there any specific reason for the same due to the
way the language is designed. Or it is discouraged due to
some specific reason. If someone can give inputs on the same, it will
be of great help.



C ++是一种低级系统语言,IMVHO,它不是GC的地方

...

C++ is a low-level systems language, IMVHO, that''s no place for a GC to
be...


11月15日上午10:32 *,Chris M. Thomasson < n ... @ spam.invalidwrote:
On Nov 15, 10:32*am, "Chris M. Thomasson" <n...@spam.invalidwrote:

< pushpakul ... @ gmail.comwrote in message


新闻:22 ********************************** @ a29g2000 pra.googlegroups.com ...
<pushpakul...@gmail.comwrote in message

news:22**********************************@a29g2000 pra.googlegroups.com...

大家好,
Hi all,


在C ++中可以进行垃圾收集。
Is garbage collection possible in C++.



当然:

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


它没有'这是

语言支持的一部分。由于

方式设计语言,是否有任何具体原因。或者由于某些特定原因而不鼓励它。如果有人可以提供相同的输入,它将是非常有帮助的。
It doesn''t come as part of
language support. Is there any specific reason for the same due to the
way the language is designed. Or it is discouraged due to
some specific reason. If someone can give inputs on the same, it will
be of great help.



C ++是一种低级系统语言,IMVHO,它不适用于GC来支付
...


C++ is a low-level systems language, IMVHO, that''s no place for a GC to
be...



查看: http://www.research.att.com/~bs/bs_f...age-collection


- bharath


pu ********** @ gmail。 com 写道:

在C ++中可以进行垃圾收集。它不是

语言支持的一部分。由于

方式设计语言,是否有任何具体原因。或者由于某些特定原因而不鼓励它。如果有人可以提供相同的输入,它将是非常有帮助的。
Is garbage collection possible in C++. It doesn''t come as part of
language support. Is there any specific reason for the same due to the
way the language is designed. Or it is discouraged due to
some specific reason. If someone can give inputs on the same, it will
be of great help.



我绝对没有第三方垃圾收集器的经验

C ++。然而,我一直想知道的是,那些可以处理

的情况如下:


int * foo()

{

int * table = new int [100];

返回表+ 40;

}


当foo()

终止时,指向已分配数组开头的指针会死,但指向其中一个元素的指针超出了范围

of foo( )。该指针可用于调用代码。一个垃圾

收藏家必须:


1)知道还有一个指向的实时指针(一个元素

inside)数组,因此它无法销毁它。


2)知道正确删除数组(即从原始指针中删除

指向数组的开头,而不是那个返回指针死亡并且GC运行的时间比那个生命长的时间更长的时间。


我想他们已经找到了这些问题。我只是想知道如何。

I have absolutely no experience in third-party garbage collectors for
C++. What I have always wondered, though, is how those can handle a
situation like:

int* foo()
{
int* table = new int[100];
return table+40;
}

The pointer to the beginning of the allocated array dies when foo()
terminates, but a pointer to one of its elements lives beyond the scope
of foo(). This pointer may be used in the calling code. A garbage
collector would have to:

1) Know that there''s still a live pointer pointing to (an element
inside) the array, and thus it cannot destroy it yet.

2) Know to delete the array properly (ie. from the original pointer
pointing to the beginning of the array, rather than the one which lived
longer than that) when that returned pointer dies and the GC runs.

I suppose they have figured out these problems. I''m just wondering how.


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

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