avatar
r*q
1
这里很多人怀疑我的方法是否有效。不是我不想写出来,
而是实在太简单,实在不值得写出来。我个人认为是个人
都应该想得出。这些人无法想出的原因,我个人认为并不
是水平不够,而是已走火入魔。在MFC和类似环境熏陶下
成长的程序员,习惯了用最复杂的方法完成最简单的认为,
而不能理解世界上还有如此简单的方法。
由于我明天要赶飞机,今天没有时间把我的方法写出来。
虽然简单,要说明白还是要不少的文字。我在此只能重申
一下,我的方法只用构造函数和析构函数,唯一原则是
不用"裸"的new/delete/alloc...
过两天如有时间我会把我的方法写出来。我并不企望能改变
那些已经走火入魔的人,只希望尚未走火入魔的人少一些误
入歧途。在这几天也许有人已经找到解决方案,如你能代我
写出来最好了,因为我很快又要回中国,行程很紧。
在此不由得联想到版名,"欲练此功,引刀自宫",对那些
走火入魔的人,可能确实如此//hehe
avatar
t*l
2
真是唐。不过还是很期待看到你的方法,多谢

【在 r*******q 的大作中提到】
: 这里很多人怀疑我的方法是否有效。不是我不想写出来,
: 而是实在太简单,实在不值得写出来。我个人认为是个人
: 都应该想得出。这些人无法想出的原因,我个人认为并不
: 是水平不够,而是已走火入魔。在MFC和类似环境熏陶下
: 成长的程序员,习惯了用最复杂的方法完成最简单的认为,
: 而不能理解世界上还有如此简单的方法。
: 由于我明天要赶飞机,今天没有时间把我的方法写出来。
: 虽然简单,要说明白还是要不少的文字。我在此只能重申
: 一下,我的方法只用构造函数和析构函数,唯一原则是
: 不用"裸"的new/delete/alloc...

avatar
c*r
3
我猜想这方法就是wrapping new/delete with constructor/destructor,
thus forcing delete/release be called when the function exists.
这样可以避免在一个function里分配和释放没有配对出现引起的内存泄露.
但更多情况下内存泄露的原因是的objects that live across functions,
especial across modules, layers, threads, ...

【在 t*****l 的大作中提到】
: 真是唐。不过还是很期待看到你的方法,多谢
avatar
w*r
4

Come on, if it's really that simple, it would cost you less time
than typing all these chinese characters.

【在 r*******q 的大作中提到】
: 这里很多人怀疑我的方法是否有效。不是我不想写出来,
: 而是实在太简单,实在不值得写出来。我个人认为是个人
: 都应该想得出。这些人无法想出的原因,我个人认为并不
: 是水平不够,而是已走火入魔。在MFC和类似环境熏陶下
: 成长的程序员,习惯了用最复杂的方法完成最简单的认为,
: 而不能理解世界上还有如此简单的方法。
: 由于我明天要赶飞机,今天没有时间把我的方法写出来。
: 虽然简单,要说明白还是要不少的文字。我在此只能重申
: 一下,我的方法只用构造函数和析构函数,唯一原则是
: 不用"裸"的new/delete/alloc...

avatar
w*r
5

How do you wrap new in the constructor?
What if you forget to call delete() in the destructor?

【在 c*r 的大作中提到】
: 我猜想这方法就是wrapping new/delete with constructor/destructor,
: thus forcing delete/release be called when the function exists.
: 这样可以避免在一个function里分配和释放没有配对出现引起的内存泄露.
: 但更多情况下内存泄露的原因是的objects that live across functions,
: especial across modules, layers, threads, ...

avatar
g*g
6
I doubt there's any simple way to do that.
Otherwise it could be automatically generated by compiler.
It takes a live VM to do that job.
If you use STL exclusively however, can relieve the burden.

【在 c*r 的大作中提到】
: 我猜想这方法就是wrapping new/delete with constructor/destructor,
: thus forcing delete/release be called when the function exists.
: 这样可以避免在一个function里分配和释放没有配对出现引起的内存泄露.
: 但更多情况下内存泄露的原因是的objects that live across functions,
: especial across modules, layers, threads, ...

avatar
c*e
7
there is no need to doubt about that.
if one wants to trade managebility with effeciency, definitely u can do that
or maybe just switch to java persay.

【在 g*****g 的大作中提到】
: I doubt there's any simple way to do that.
: Otherwise it could be automatically generated by compiler.
: It takes a live VM to do that job.
: If you use STL exclusively however, can relieve the burden.

avatar
N*r
8
the point is that C++ code does not run a VM, so there is no way
to write a garbage collecter on par with the one in Java.
Without changing the language, a garbage collector for C++ will be
either incomplete, or inefficient compared to the Java one.

【在 c********e 的大作中提到】
: there is no need to doubt about that.
: if one wants to trade managebility with effeciency, definitely u can do that
: or maybe just switch to java persay.

avatar
a*f
9
I think an pair of overloaded new and delete functions could be pretty helpful
in many cases. It records each allocated/deallocated memory block and
the statement allocating/deleting it. After the main program is ended, it could
output the memory blocks which have not been released yet and the corresponding
statements allocating them.
Besides, we could cache the memory blocks if your program allocate/deallocate
small memory blocks frequently, and the performance fo the program could be
improved

【在 N*********r 的大作中提到】
: the point is that C++ code does not run a VM, so there is no way
: to write a garbage collecter on par with the one in Java.
: Without changing the language, a garbage collector for C++ will be
: either incomplete, or inefficient compared to the Java one.

avatar
c*r
10
This is way to detect/debug memory leakage, not a way to avoid it.

helpful
could
corresponding
deallocate
code.
of

【在 a***f 的大作中提到】
: I think an pair of overloaded new and delete functions could be pretty helpful
: in many cases. It records each allocated/deallocated memory block and
: the statement allocating/deleting it. After the main program is ended, it could
: output the memory blocks which have not been released yet and the corresponding
: statements allocating them.
: Besides, we could cache the memory blocks if your program allocate/deallocate
: small memory blocks frequently, and the performance fo the program could be
: improved

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。