Programming 2D Games

The official forum for "Programming 2D Games" the book by: Charles Kelly

It is currently Fri Nov 16, 2018 2:54 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Dynamic Arrays
PostPosted: Sun Dec 30, 2012 12:30 am 
Offline

Joined: Tue Dec 11, 2012 8:04 pm
Posts: 36
OK, great, thanks.

_________________
Nick


Top
 Profile  
Reply with quote  
 Post subject: Re: Dynamic Arrays
PostPosted: Mon Aug 10, 2015 5:25 pm 
Offline

Joined: Sun Aug 02, 2015 2:52 pm
Posts: 15
In §3 the text introduces the C RTL debug header and the call to the memory tracker

Code:
#include "crtdbg.h"      // for detecting memory leaks
...
#if defined(DEBUG) | defined(_DEBUG)
   ::_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif


But you get output that isn't that obvious

Code:
Detected memory leaks!
Dumping objects ->
{112} normal block at 0x00AF2188, 16 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
The program '[9616] exdynamicmemory.exe: Native' has exited with code 0 (0x0).


You can decode this but there is an easier way.

Code:
// exdynamicmemory.cpp : demonstrate memory debugging
//

#include "stdafx.h"
#include "crtdbg.h"      // for detecting memory leaks

#ifdef _DEBUG
   #ifndef DBG_NEW
      #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
      #define new DBG_NEW
   #endif
#endif  // _DEBUG

void leak()
{
   new char[16];   // leak memory
}

int _tmain(int /*argc*/, _TCHAR* /*argv*/[])
try
{
#if defined(DEBUG) | defined(_DEBUG)
   ::_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

   leak();      // inject memory leak

   return 0;
} catch(...) {
   return 1;
}


now you get

Code:
Detected memory leaks!
Dumping objects ->
.\exdynamicmemory.cpp(16) : {112} normal block at 0x00892188, 16 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
The program '[9284] exdynamicmemory.exe: Native' has exited with code 0 (0x0).


You can double click the line to go directly to the allocation line.

This only deals with C RTL allocations. It will not detect DirectX leaks. That is for another post.

-tim


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group