y*******o 发帖数: 6632 | 1 1. if you have a program including hundreds of files, how do you detect and
debug the memory leak?
2. How should you debug your code if your programs crash during the program
loading?
These two questions I met recently in my interview, I do not know what is
the correct answer for them. Anyone can help? |
s*w 发帖数: 729 | 2 1. 就是问你是否熟悉常用的 memory error detection tools, 比如 valgrind; 如果
你没
编过大点的程序,显然没用过
2. 不会,貌似出错范围太大了;小程序自然是 step through line by line, 如果
都 load
不进去,大约是没内存空间放 code binary 或者 需要的 global variable 了;似乎
和 stack
没关系
and
program
is
【在 y*******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 1. if you have a program including hundreds of files, how do you detect and : debug the memory leak? : 2. How should you debug your code if your programs crash during the program : loading? : These two questions I met recently in my interview, I do not know what is : the correct answer for them. Anyone can help?
|
y*******o 发帖数: 6632 | 3 well for question 1, my answer is override the operator new. But I do not
how to do so.
I find the following link:
http://www.flipcode.com/archives/How_To_Find_Memory_Leaks.shtml
something like
#ifdef _DEBUG
#define DEBUG_NEW new(__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif
#define new DEBUG_NEW
Do you think this would be a good answer for the question?
【在 s*w 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 1. 就是问你是否熟悉常用的 memory error detection tools, 比如 valgrind; 如果 : 你没 : 编过大点的程序,显然没用过 : 2. 不会,貌似出错范围太大了;小程序自然是 step through line by line, 如果 : 都 load : 不进去,大约是没内存空间放 code binary 或者 需要的 global variable 了;似乎 : 和 stack : 没关系 : : and
|
X****r 发帖数: 3557 | 4 This is not overriding. It is lexical replacement. It would make code
uncompilable if placement new is used.
【在 y*******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : well for question 1, my answer is override the operator new. But I do not : how to do so. : I find the following link: : http://www.flipcode.com/archives/How_To_Find_Memory_Leaks.shtml : something like : #ifdef _DEBUG : #define DEBUG_NEW new(__FILE__, __LINE__) : #else : #define DEBUG_NEW new : #endif
|
y*******o 发帖数: 6632 | 5 another question is that if any class use a self defined operator new, the
file will not compile too. Right?
So if it does not work, what is the correct answer for this question? Thanks
a lot.
【在 X****r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : This is not overriding. It is lexical replacement. It would make code : uncompilable if placement new is used.
|
s*w 发帖数: 729 | 6 of course u can override the default operator new by providing your own
version. But your macro above is not overriding. It works to a certain
degree but there is better way to do it.
When one faces the problem of finding memory leaks, the solution is not to
program one's own tool but to use an existing tool. I do not think the
interviewer expect to hear how to program this tool, coz that shows you
have not ever used any such tool. You only do that when existing tools
cannot solve your problem.
the
Thanks
【在 y*******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : another question is that if any class use a self defined operator new, the : file will not compile too. Right? : So if it does not work, what is the correct answer for this question? Thanks : a lot.
|
y*******o 发帖数: 6632 | 7 you are right. I think this macro way also missed the point about new[] and
delete[]. So could you please recommend any tools in linux or saloris to
learn? thanks.
Valgrin?
【在 s*w 的大作中提到】![](/moin_static193/solenoid/img/up.png) : of course u can override the default operator new by providing your own : version. But your macro above is not overriding. It works to a certain : degree but there is better way to do it. : When one faces the problem of finding memory leaks, the solution is not to : program one's own tool but to use an existing tool. I do not think the : interviewer expect to hear how to program this tool, coz that shows you : have not ever used any such tool. You only do that when existing tools : cannot solve your problem. : : the
|
b********n 发帖数: 609 | 8 valgrind是最好用的,另外一些profiler也可以。
and
【在 y*******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : you are right. I think this macro way also missed the point about new[] and : delete[]. So could you please recommend any tools in linux or saloris to : learn? thanks. : Valgrin?
|
k*******d 发帖数: 1340 | 9 Valgrin好像只有Linux版的,Windows下用啥?
从根本上解决还是用smart pointer吧
第二个问题,可能是全局变量的constructor 出问题? 在那些constructor里面设置断
点?如果这还找不到,那就不知道怎么办了。。 |
t****u 发帖数: 8614 | 10 第二个问题,很简单,有crash dump,call stack调出来,95%以上的case,
能找出问题.
第一个问题,不懂考官的目的,用glowcode查就行了,大部分情况能identify那部分
code有memory leak.
【在 k*******d 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Valgrin好像只有Linux版的,Windows下用啥? : 从根本上解决还是用smart pointer吧 : 第二个问题,可能是全局变量的constructor 出问题? 在那些constructor里面设置断 : 点?如果这还找不到,那就不知道怎么办了。。
|
|
|
k*******d 发帖数: 1340 | 11 这个crash dump是存在哪里的呢?
【在 t****u 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 第二个问题,很简单,有crash dump,call stack调出来,95%以上的case, : 能找出问题. : 第一个问题,不懂考官的目的,用glowcode查就行了,大部分情况能identify那部分 : code有memory leak.
|
s****a 发帖数: 238 | 12 mac的是在/cores里,linux不清楚,可能在原目录里
之前要用ulimit -c unlimited把核心文件的大小限制去掉,有的系统默认是0
【在 k*******d 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 这个crash dump是存在哪里的呢?
|
k*******d 发帖数: 1340 | 13 恩,试了一下,Fedora不在原目录,在var/cache/abrt
Windows有此类的东西么?
【在 s****a 的大作中提到】![](/moin_static193/solenoid/img/up.png) : mac的是在/cores里,linux不清楚,可能在原目录里 : 之前要用ulimit -c unlimited把核心文件的大小限制去掉,有的系统默认是0
|
t****u 发帖数: 8614 | 14 我老只知道Windows,您老可以自己设的,default在C:\Windows下。
Win7之前,可以用DrWstn32设置。Win7用WEP的registry setting。
【在 k*******d 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 这个crash dump是存在哪里的呢?
|
h***i 发帖数: 1970 | 15 对于memory leak,强烈推荐totalview,找起来简直是太容易了。
【在 t****u 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 第二个问题,很简单,有crash dump,call stack调出来,95%以上的case, : 能找出问题. : 第一个问题,不懂考官的目的,用glowcode查就行了,大部分情况能identify那部分 : code有memory leak.
|