Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualfastcall22

Posted 11 September 2012 - 10:51 AM

extern unsigned int _gCurLine;
extern char* _gCurFile;

#define MEM_FUNC_CALL _gCurLine=__LINE__; _gCurFile=(char*)__FILE__;


Posted Image

For instance, try the following code:
#include "MemoryHandler.h"
#include <iostream>

class A { };

class B {
public:
    B() { MEM_FUNC_CALL a = new A(); }
    ~B() { MEM_FUNC_CALL delete a; }

private:
   B( const B& );
   B& operator= ( const B& );

private:
	A* a;
};

int main( int, char*[] ) {
    B* b = 0;
    if ( false )
        MEM_FUNC_CALL b = new B;

    EndOfProgramMemCheck();
}

You can also override new and new[] to include additional parameters and use a macro to hijack all calls to new and delete to call your overloaded version, without needing to remember to use MEM_FUNC_CALL. (Though, you do need to make sure that the macros are defined in each compilation unit.) Take a look at a demonstration of memory leak detection for Visual Studio on MSDN. It should give you some ideas.

Also:
Those aren't trees, those are linked lists :|

#4fastcall22

Posted 11 September 2012 - 10:44 AM

extern unsigned int _gCurLine;
extern char* _gCurFile;

#define MEM_FUNC_CALL _gCurLine=__LINE__; _gCurFile=(char*)__FILE__;


Posted Image

For instance, try the following code:
#include "MemoryHandler.h"
#include <iostream>

class A { 
    A() { std::cout << "New A at " << this << '\n'; }
    ~A() { std::cout << "Delete A at " << this << '\n'; }
};

class B {
public:
    B() { MEM_FUNC_CALL a = new A(); }
    ~B() { delete a; }

private:
   B(const B&);
   B& operator= ( const B& );

private:
	A* a;
}

int main( int, char*[] ) {
    A* a = 0;
    if ( false )
        MEM_FUNC_CALL a = new A;
    delete a;

    if ( false )
        MEM_FUNC_CALL delete new B;

    EndOfProgramMemCheck();
}

You can also override new and new[] to include additional parameters and use a macro to hijack all calls to new and delete to call your overloaded version, without needing to remember to use MEM_FUNC_CALL. (Though, you do need to make sure that the macros are defined in each compilation unit.) Take a look at a demonstration of memory leak detection for Visual Studio on MSDN. It should give you some ideas.

Also:
Those aren't trees, those are linked lists :|

#3fastcall22

Posted 11 September 2012 - 10:15 AM

extern unsigned int _gCurLine;
extern char* _gCurFile;

#define MEM_FUNC_CALL _gCurLine=__LINE__; _gCurFile=(char*)__FILE__;


Posted Image

For instance, try the following code:
#include "MemoryHandler.h"

class A { };
class B {
public:
    B() { MEM_FUNC_CALL a = new A(); }
    ~B() { delete a; }

private:
   B(const B&);
   B& operator= ( const B& );

private:
	A* a;
}

int main( int, char*[] ) {
    if ( false )
        MEM_FUNC_CALL delete new B;
    EndOfProgramMemCheck();
}

You can also override new and new[] to include additional parameters and use a macro to hijack all calls to new and delete to call your overloaded version, without needing to remember to use MEM_FUNC_CALL. (Though, you do need to make sure that the macros are defined in each compilation unit.) Take a look at a demonstration of memory leak detection for Visual Studio on MSDN. It should give you some ideas.

Also:
Those aren't trees, those are linked lists :|

#2fastcall22

Posted 11 September 2012 - 10:14 AM

extern unsigned int _gCurLine;
extern char* _gCurFile;

#define MEM_FUNC_CALL _gCurLine=__LINE__; _gCurFile=(char*)__FILE__;


Posted Image

For instance, try the following code:
#include "MemoryHandler.h"

class A { };
class B {
public:
    B() { MEM_FUNC_CALL a = new A(); }
    ~B() { delete a; }

private:
   B(const B&);
   B& operator= ( const B& );

private:
	A* a;
}

int main( int, char*[] ) {
    if ( false )
        MEM_FUNC_CALL delete new B;
    EndOfProgramMemCheck();
}

You can also override new and new[] to include additional parameters and use a macro to hijack all calls to new and delete to call your overloaded version, as demonstrated in memory leak detection for Visual Studio on MSDN.Posted Image

Also:
Those aren't trees, those are linked lists :|

#1fastcall22

Posted 11 September 2012 - 10:09 AM

extern unsigned int _gCurLine;
extern char* _gCurFile;

#define MEM_FUNC_CALL _gCurLine=__LINE__; _gCurFile=(char*)__FILE__;


Posted Image

class A { };
class B {
public:
	B() { MEM_FUNC_CALL a = new A(); }
	~B() { delete a; }

private:
   B(const B&);
   B& operator= ( const B& );

private:
	A* a;
}

int main( int, char*[] ) {
	if ( false )
		MEM_FUNC_CALL delete new B;
	EndOfProgramMemCheck();
}

You can also override new and new[] to include additional parameters and use a macro to hijack all calls to new and delete to call your overloaded version, as demonstrated in memory leak detection for Visual Studio on MSDN.Posted Image

Also:
Those aren't trees, those are linked lists :|

PARTNERS