GCC memory leak detection equivalent to Microsoft crtdbg.h?

后端 未结 7 2118
悲&欢浪女
悲&欢浪女 2020-12-13 04:41

After many years of working on a general-purpose C++ library using the Microsoft MSVC compiler in Visual Studio, we are now porting it to Linux/Mac OS X (pray for us). I hav

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 04:57

    I'm not aware of anything "built-in" that does what you describe, but it doesn't seem like it would be very hard to "roll your own" version of this. You just want your debugging new to record the pointer, file and line in a map where the key is the allocated pointer and the value (AllocationInfo) would be some struct that holds the filename, line number, etc. You also need to define a custom delete operator that checks the map for the pointer being deleted. If found, that entry is removed from the map. Then at process shutdown time you emit the contents of the map.

    I found a page where someone describes their own home-grown system that works like this.

提交回复
热议问题