由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Two classic C++ questions, how to answer
相关主题
急问:大家一般都用什么profiling工具和memory leak的监测工有什么办法可以查每行代码用的时间?
[合集] 急问:大家一般都用什么profiling工具和memory leak的监Urgent help on how to get statistical informaiton of an algorithm
Memory Usage问题请问这是什么语法(C++)?
大家都用什么工具来profile C/C++程序有没有工具自动描绘C++程序的Call flow
怎么样profile C++ code最好?C++ Profiler
java jvm 问题这个go的吐槽很客观
各位给推荐一个C++ programming performance profiler?gprof和STL的问题
如何查看一个程序里面某个函数或者计算占用的CPU和内存?code profiling 的问题
相关话题的讨论汇总
话题: debug话题: new话题: answer话题: two话题: do
进入Programming版参与讨论
1 (共1页)
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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: Valgrin好像只有Linux版的,Windows下用啥?
: 从根本上解决还是用smart pointer吧
: 第二个问题,可能是全局变量的constructor 出问题? 在那些constructor里面设置断
: 点?如果这还找不到,那就不知道怎么办了。。

相关主题
java jvm 问题有什么办法可以查每行代码用的时间?
各位给推荐一个C++ programming performance profiler?Urgent help on how to get statistical informaiton of an algorithm
如何查看一个程序里面某个函数或者计算占用的CPU和内存?请问这是什么语法(C++)?
进入Programming版参与讨论
k*******d
发帖数: 1340
11
这个crash dump是存在哪里的呢?

【在 t****u 的大作中提到】
: 第二个问题,很简单,有crash dump,call stack调出来,95%以上的case,
: 能找出问题.
: 第一个问题,不懂考官的目的,用glowcode查就行了,大部分情况能identify那部分
: code有memory leak.

s****a
发帖数: 238
12
mac的是在/cores里,linux不清楚,可能在原目录里
之前要用ulimit -c unlimited把核心文件的大小限制去掉,有的系统默认是0

【在 k*******d 的大作中提到】
: 这个crash dump是存在哪里的呢?
k*******d
发帖数: 1340
13
恩,试了一下,Fedora不在原目录,在var/cache/abrt
Windows有此类的东西么?

【在 s****a 的大作中提到】
: mac的是在/cores里,linux不清楚,可能在原目录里
: 之前要用ulimit -c unlimited把核心文件的大小限制去掉,有的系统默认是0

t****u
发帖数: 8614
14
我老只知道Windows,您老可以自己设的,default在C:\Windows下。
Win7之前,可以用DrWstn32设置。Win7用WEP的registry setting。

【在 k*******d 的大作中提到】
: 这个crash dump是存在哪里的呢?
h***i
发帖数: 1970
15
对于memory leak,强烈推荐totalview,找起来简直是太容易了。

【在 t****u 的大作中提到】
: 第二个问题,很简单,有crash dump,call stack调出来,95%以上的case,
: 能找出问题.
: 第一个问题,不懂考官的目的,用glowcode查就行了,大部分情况能identify那部分
: code有memory leak.

1 (共1页)
进入Programming版参与讨论
相关主题
code profiling 的问题怎么样profile C++ code最好?
MATLAB function call too slowjava jvm 问题
visual studio 2005怎么code profiling?各位给推荐一个C++ programming performance profiler?
【讨论】Linux启动时执行配置文件的顺序 (转载)如何查看一个程序里面某个函数或者计算占用的CPU和内存?
急问:大家一般都用什么profiling工具和memory leak的监测工有什么办法可以查每行代码用的时间?
[合集] 急问:大家一般都用什么profiling工具和memory leak的监Urgent help on how to get statistical informaiton of an algorithm
Memory Usage问题请问这是什么语法(C++)?
大家都用什么工具来profile C/C++程序有没有工具自动描绘C++程序的Call flow
相关话题的讨论汇总
话题: debug话题: new话题: answer话题: two话题: do