avatar
撞见老公出轨后# Love - 情爱幽幽
y*o
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?
avatar
m*i
2
我跟老公都住在公司附近,但是我们公司有食堂,一般,我中午不愿意回家,就在
食堂吃午饭的。
老公本来也不回家的,可是最近他说在外面吃饭太贵,所以他要回家做饭吃,健康
还便宜,我还感慨,老公终于长大了。
有天中午,我们老板请我们吃饭,庆祝项目通过,吃完后。我就打包了一份老公爱
吃的菜,准备给他送回去。
然后,我就急急忙忙的带回去了,回家拿出钥匙开门,门怎么也打不开,我还纳闷
这是怎么了,我窍门也没有人给我开门,我给老公打电话他也没接。
后来我就给开锁公司打电话,然后门突然就开了。
估计是我老公听见我打电话的声音,才开门的。
进屋后,我发现一个女人从浴室里出来。我放下菜准备离开,老公拉上我跟我道歉
。我说还有必要道歉么,我们离婚吧。
老公说如果要离婚除非他死,他说自己就是鬼迷心窍,以后再也不会犯这样的错误。
人都有犯错的时候,周围的亲戚朋友都劝和不劝离。况且老公真心实意的道歉。我
也就原谅他了。
可是,最近我发现,他总是在阳台上打电话,一打就是一个多小时,声音还特温柔
,问他怎么回事,他说他工作。
我觉得他又犯病了,果然狗改不了吃屎,现在正在搜集证据!!!
avatar
j*g
3
1. all options are not mutually exclusive.
option a. overload new operator or try to shim malloc so that you can track
all the memory allocations, which line of code they originate, etc. Before
program exists, check allocation lists and see if any still left and what
file and what line caused the leak.
option b. use commercial leak detection program such as boundschecker (on
windows platform).
2. depending on OS. If on windows, you can override image load option in
registry key such as the OS will launch the program into ntsd/cdb/whatever
debugger you specified, and then you can debug its loading coding. See
details at http://msdn.microsoft.com/en-us/library/a329t4ed.aspx
avatar
y*o
4
Thank you so much for your help. This is so cool.
I know that I should overload the operator new for the first question, but
do not know how and not sure if it is the correct answer at all.
This following link is very good for debug memory leak:
http://www.flipcode.com/archives/How_To_Find_Memory_Leaks.shtml

track

【在 j*****g 的大作中提到】
: 1. all options are not mutually exclusive.
: option a. overload new operator or try to shim malloc so that you can track
: all the memory allocations, which line of code they originate, etc. Before
: program exists, check allocation lists and see if any still left and what
: file and what line caused the leak.
: option b. use commercial leak detection program such as boundschecker (on
: windows platform).
: 2. depending on OS. If on windows, you can override image load option in
: registry key such as the OS will launch the program into ntsd/cdb/whatever
: debugger you specified, and then you can debug its loading coding. See

avatar
s*n
5

and
why hundreds of files are different?
program
if it is crash during loading and you cannot attach the debugger at
beginning
then it can be dll loading issue. add instrumentation code to reveal the
issue.
Otherwise, just luanch the app with a debugger, stop at the first
instruction,
then p.

【在 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?

avatar
j*g
6
code base size matters because for small mini hello world project, it's
relatively easy to track down leaks by eyeballing and manual debugging. for
hundred K-lines or million-lines of code, you need a systematic way to track
, record, dump and report leaks. Size matters, dude!
J

【在 s*****n 的大作中提到】
:
: and
: why hundreds of files are different?
: program
: if it is crash during loading and you cannot attach the debugger at
: beginning
: then it can be dll loading issue. add instrumentation code to reveal the
: issue.
: Otherwise, just luanch the app with a debugger, stop at the first
: instruction,

avatar
y*o
7
this is not a ideal way according to some bull in programming board.
First, doing so will cause the placement and operator new override in some
classes uncompilable.
Second, it missed the leaks from new[] and delete[].

track

【在 j*****g 的大作中提到】
: 1. all options are not mutually exclusive.
: option a. overload new operator or try to shim malloc so that you can track
: all the memory allocations, which line of code they originate, etc. Before
: program exists, check allocation lists and see if any still left and what
: file and what line caused the leak.
: option b. use commercial leak detection program such as boundschecker (on
: windows platform).
: 2. depending on OS. If on windows, you can override image load option in
: registry key such as the OS will launch the program into ntsd/cdb/whatever
: debugger you specified, and then you can debug its loading coding. See

avatar
j*g
8
Actually in your linked article, he mentioned you need to override new[]
delete[] as well.
Yes, this solution isn't ideal, but given you can't shim the underlying OS
heap calls (such as using BoundsChecker), then this is perhaps the best you
can get.
J

【在 y*******o 的大作中提到】
: this is not a ideal way according to some bull in programming board.
: First, doing so will cause the placement and operator new override in some
: classes uncompilable.
: Second, it missed the leaks from new[] and delete[].
:
: track

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