指针经理? [英] pointers manager ?

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

问题描述

嗨!


我想知道是否有工具可以告诉我,如果他们的某些我的

指针仍然存在死了(以防万一我不想杀死他们......)。


正如你所注意到的,我是c ++编程的真正新手,我有

很难记住哪个指针应该存活哪一个

应该死(Java垃圾收集器故障......)。


非常感谢!!


Marcelo

Hi !

I was wondering if there is tool that could tell me if some of my
pointers are still alive when they are suppose to be dead (in case I
forget to kill them...).

As you have noticed, I am real newbie in c++ programming and I have
quite a trouble to remember which pointer should be alive and which one
should die (Java garbage collector fault...).

Thanks a lot !!

Marcelo

推荐答案

嗯....

不幸的是C ++不提供垃圾收集...

你必须手动删除你所有的指针..无论你有哪个

分配......


但是有很好的解决方法......

使用Boost C ++库,你可以使用shared_ptr<>

使用你的d 不得不担心它的释放...... :)


4月20日晚上8:54,Marcelo Fernandez< marche_1 ... @ hotm ail.comwrote:
Hmmm....
Unfortunately C++ dont provide garbage collection...
U have to manually delete all your pointers ..whichever you have
allocated...

But there is good workaround for that...
Use Boost C++ library, you can use shared_ptr<>
Using that you d''nt have to worry for its deallocation...:)

On Apr 20, 8:54 pm, Marcelo Fernandez <marche_1...@hotmail.comwrote:

嗨!


我想知道是否有工具可以告诉我是否有一些

指针在它们被假死时仍然存活(如果我是
忘记杀死它们......)。


正如你已经注意到的那样,我是c ++编程的真正新手,我有一个很难记住哪个指针应该存活以及哪一个

应该死掉(Java垃圾)收藏家的错误......)。


非常感谢!!

Marcelo
Hi !

I was wondering if there is tool that could tell me if some of my
pointers are still alive when they are suppose to be dead (in case I
forget to kill them...).

As you have noticed, I am real newbie in c++ programming and I have
quite a trouble to remember which pointer should be alive and which one
should die (Java garbage collector fault...).

Thanks a lot !!

Marcelo



Marcelo Fernandez写道:
Marcelo Fernandez wrote:

我想知道是否有工具可以告诉我是否有些我的

指针在它们被假死时仍然存活(如果我是
忘记杀死它们......)。


你有注意到,我是c ++编程中真正的新手,我要记住哪个指针是很麻烦的我应该还活着,哪一个应该死掉(Java垃圾收集器故障......)。
I was wondering if there is tool that could tell me if some of my
pointers are still alive when they are suppose to be dead (in case I
forget to kill them...).

As you have noticed, I am real newbie in c++ programming and I have
quite a trouble to remember which pointer should be alive and which
one should die (Java garbage collector fault...).



有两种方法:学会管理他们的生命周期

或使用垃圾收集器。有管理生命周期的规则

的动态对象,我打赌书谈论它们(比如所有权,

引用计数...),你只需要找到正确的书。对于垃圾收集器来说,

市场上有几种实现方式,只需要查找它们。


没有工具这可以判断指针何时假定为
死。有一些工具可以识别在程序运行完毕后从未被释放的内存。这些被称为

内存泄漏检测器。查看它们。


V

-

请在通过电子邮件回复时删除资金'A'

我没有回复最热门的回复,请不要问

There are two approaches: either learn to manage their lifetime
or use a garbage collector. There are rules for managing lifetime
of dynamic objects, and I bet books talk about them (like ownership,
reference counting...), you just need to find the right book. As
for garbage collector, there are several implementations on the
market, just look for them.

There are no tools that can tell when the pointer "are suppose to be
dead". There are tools that can identify memory that has never been
deallocated after the program has finished running. Those are called
"memory leak detector". Look them up.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


2007-04-20 17:54,Marcelo Fernandez写道:
On 2007-04-20 17:54, Marcelo Fernandez wrote:

嗨!


我想知道是否有工具可以告诉我是否有一些我的

指针在它们被假死时仍然存活(如果我是/ b $ b忘记杀死它们......)。
Hi !

I was wondering if there is tool that could tell me if some of my
pointers are still alive when they are suppose to be dead (in case I
forget to kill them...).



这些东西都有工具,我不知道它们究竟有多好

因为我只使用了一两个相当简单的程序。我做了什么

记住,他们花了很长时间才使用,因为他们基本上是通过调试器和堆上的每个分配来运行程序
$

它记录了分配的内存地址和代码行。


一个这样的工具叫做Valgrind,电子围栏是另一个。

There are tools for such things, I don''t know exactly how good they are
since I only used one or two on fairly simple programs. What I do
remember was that they took quite some time to use since they basically
run the program through a debugger and for each allocation on the heap
it recorded the memory address and line of code that made the allocation.

One such tool is called Valgrind, electrical fence is another.


正如你所注意到的,我是c ++编程中真正的新手,而且我有一个麻烦要记住哪个指针应该存活哪一个

应该死(Java垃圾收集器故障...)。
As you have noticed, I am real newbie in c++ programming and I have
quite a trouble to remember which pointer should be alive and which one
should die (Java garbage collector fault...).



一种简单的做事方式通常是避免使用动态内存

除非必要,并且当你学到更多C ++时你会看到它不是必需的,而且几乎和一个人一样频繁。事实上,人们可以写一些相当复杂的整个程序,而无需在

堆上分配内存。


既然你已经使用Java之前,你已经习惯了在创建变量时习惯使用新的

,在C ++中通常不是这样的。


另一个有用的功能C ++语言的是auto_ptr和

shared_ptr(我认为它有一个提升),它就像

指针一样工作,但它们会为你解除分配。


如果您对某些代码有特定问题,可以在这里发布

(除非它太大了)你可以得到一些评论。


-

Erik Wikstr?m

A simpler way of doing things is usually to avoid using dynamic memory
unless necessary, and as you learn more C++ you''ll see that it''s not
necessary nearly as often as one might thing. In fact one can write
whole programs of quite some complexity without allocating memory on the
heap.

Since you have been using Java earlier you have gotten used to using new
whenever you create a variable, in C++ that is generally not the way to go.

Another useful feature of the C++ language is the auto_ptr and
shared_ptr (that one comes with boost I think) which work just like
pointers but they take care of the deallocation for you.

If you have a specific problem with some code you could post it here
(unless it''s too large) and you can get some comments on it.

--
Erik Wikstr?m


这篇关于指针经理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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