Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 11 Jul 2010
Offline Last Active Aug 27 2015 03:13 PM

#4811242 [C++, VS 2010 Ultimate] Advanced memory leak detection

Posted by GhostfromTexas on 15 May 2011 - 04:32 PM

The quick answer is use another tool, like Visual Leak Detector and it will give you the location of all your leaks in the output window when the program exists.

I looked into VLD but couldn't get it to give me anymore information than I already knew...

But however I did figure out a way to make CRT work better for me thanks from some help from someone..

global header. either a forced header in visual studio or one that's included everywhere in the project by some sort of method. In Visual Studio it's under Project Settings -> c++ -> Advanced -> Forced Include File (just list the file there without quotes. This assumes you own file, not a standard library include)
//--- CRT debug header (must be last)
#if defined(DEBUG) | defined(_DEBUG)
#include <crtdbg.h>
#define new new( _NORMAL_BLOCK, __FILE__, __LINE__)
#pragma warning(disable : 4345) //this warning is when using empty () when allocating a new object. Only happens when allocating memory with this debug option, so disabling it

first line in main:
#if defined(DEBUG) | defined(_DEBUG)
//_CrtSetBreakAlloc(100); //break on a specific memory allocation

This allowed visual studio to output file and line number for the leaked allocation. The output looks something like this now:

c:\users\user\desktop\project-folder\files\file.cpp(392) : {487594} normal block at 0x087F1500, 456 bytes long.
Data: < fff?o : > CD CD CD CD 66 66 66 3F 6F 12 03 3A CD CD CD CD
{487590} normal block at 0x087F14B8, 8 bytes long.
Data: < > 1C 13 7F 08 00 00 00 00
c:\users\user\desktop\project-folder\files\file.cpp(275) : {487585} normal block at 0x087F12E0, 100 bytes long.
Data: < { > 20 14 7B 08 00 00 00 00 00 00 00 00 00 00 00 00
c:\users\user\desktop\project-folder\files\file.cpp(133) : {487578} normal block at 0x087E5038, 96 bytes long.
Data: < ;& > B8 3B 26 02 01 00 00 00 00 00 00 00 02 00 00 00

So even though i was getting random leaks, this method allow me to figured out how to track them down much easier.

Hopefully this helps some others in the future on how to fix it.

Thanks to Ghaleon from #gamedev on the #efnet IRC for this. He's the one that came up with the code

#4785901 [DX] Helpful Color List Header

Posted by GhostfromTexas on 14 March 2011 - 09:36 PM

I ended up making this for my project since I know I have a lot of colors that are randomly defined by name, so I figured I'd spend a few hours and make a really large compilation of a lot of colors that could be used throughout my project.

The header has #defines and const variables to use. Just block comment out the section you don't want.


feel free to do with this what you want.. I don't care for credit or anything, just a list I thought I'd share. The colors came from wikipedia's list of colors. So they are named accordingly there with sample colors of what it looks like. The link is in the header comment of the file.