Gcc_new ?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Hello there,

      bought the book about a week ago and love every page of it :) And I have one question about it, whats up with GCC_NEW?

      It's defined as this in the source

      Source Code

      1. // Game Code Complete - Chapter 12, page 446-447
      2. #if defined(_DEBUG)
      3. # define GCC_NEW new(_NORMAL_BLOCK,__FILE__, __LINE__)
      4. #else
      5. # define GCC_NEW new
      6. #endif


      And I looked at the pages, but it was about 3D Math, so I guess it's from 1st ed?

      Enlighten me please :)

      Best regards
      Jesper
    • GCC_NEW is a macro that defines different ways to allocate memory depending on the build mode that the compiler is in.

      In the DEBUG build,

      Source Code

      1. #if defined(_DEBUG)
      2. # define GCC_NEW new(_NORMAL_BLOCK,__FILE__, __LINE__)


      it allocates memory in such a way that a record of the allocation is kept. This allows the program to tell whether all memory is destroyed properly.

      otherwise, it's the RELEASE build,

      Source Code

      1. #else
      2. # define GCC_NEW new
      3. #endif


      Then just define GCC_NEW as the normal allocation of memory.

      Hope this somewhat clears it up.

      The post was edited 1 time, last by Alien_Attack ().

    • Originally posted by Alien_Attack
      Ya, sorry. That was a kind of vague description.

      These functions are part of the windows CRT Debug heap. It's not part of GCC code that you missed! It's just something provided by Microsoft for debugging the heap and thus helping in finding memory leaks.

      More info can be found here:
      msdn.microsoft.com/library/def…ites_and_memory_leaks.asp



      Hello Alien_Attack,

      I'm sorry to bother you, but it sounds so cool and I want to understand it.
      I read the MSDN link you provided, and it didn't make my mind any clearer.

      I tried to make a test app that defined the macro as in GCC, and I included crtdbg.h, and tried to allocate 20 objects with the GCC_NEW and not delet them.

      But the debug console didn't say anything. I guess this is not all thats needed?

      /Jesper
    • Look in the 2nd edition on pp 724-725 and you'll get a complete description of what your looking for - you need to call some of the debug memory heap APIs, such as _CrtDumpMemoryLeaks().
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • There's an awesome memory leak detector called Visual Leak Detector. I found it while poking around on The Code Project:
      codeproject.com/tools/visualleakdetector.asp

      I like it because it's very low-maintenance. All you have to do is put it as a top-level include in your source code (stdafx.h or something similar). It takes care of the lib linking itself and only exists in the debug build. I use it pretty much everywhere.

      -Rez