wierd delete [ ] myClass exception. Need Help PLZ! [modified]
-
Hi all, well allthough I'm new to C++ I've done my share of development in more user friendly environments, mainly C#. Anyhow I want to learn C++ as mainly personal interest as my professional life will be focused primarly in .NET development whenever it is needed. To learn the basics of the language I'm starting with a real easy Math class that will initially implement a Matrix (no templates). Nothing fancy but an easy place to start to at least start learning Object Oriented programming in C++ like any other. Well the thing is that I'm completely stumped with an error I'm getting. I've created a simple Win32 console app that links my FastMath.dll and uses the FMatrix class defined inside. Test app code is as simple as it can get, it only instantiates one FMatrix and then deletes it, and something that simple is giving me a runtime error. Here's the code in the tesp app:
#include "stdafx.h" #include "FMatrix.h" using namespace FastMath; using namespace std; int _tmain(int argc, _TCHAR* argv[]) { FMatrix *a=new FMatrix(5); cout << "A is a [" << a->GetRowCount() << "x" << a->GetColumnCount() << "] matrix." << endl; delete a; return 0; }
Ok the error I'm getting is when executing "delete a". The error message is:Windows has triggered a breakpoint in Tester.exe.
This may be due to a corruption of the heap, and indicates a bug in Tester.exe or any of the DLLs it has loaded.
The output window may have more diagnostic informationIf I try to continue I get the same error once and then succesive Assertion Failed error messages: "Expression: _CrtIsValidHeapPointer(pUserData)" and if I ignore that I get a HEAP CORRUPTION DETECTED error message "CRT detected that the application wrote to memory after end of heap buffer." I really do not understand what I'm doing wrong in my FMatrix file. I'm including header and source files below: FMatrix.h
#ifdef FASTMATH_EXPORTS #define FASTMATH_API __declspec(dllexport) #else #define FASTMATH_API __declspec(dllimport) #endif #pragma once #include "StdAfx.h" namespace FastMath { class FASTMATH_API FMatrix { private: int rw,cl; double *val; FMatrix(void); FMatrix(unsigned int,bool); FMatrix(unsigned int,unsigned int,bool); void initMatrix(unsigned int,unsigned int,bool); void destroy(void); public: FMatrix(const FMatrix&); //copy constructor FMatrix(unsigned int); FMatrix(unsigned int,unsigned int); FMatrix(unsigned int,unsigned int,double
-
Hi all, well allthough I'm new to C++ I've done my share of development in more user friendly environments, mainly C#. Anyhow I want to learn C++ as mainly personal interest as my professional life will be focused primarly in .NET development whenever it is needed. To learn the basics of the language I'm starting with a real easy Math class that will initially implement a Matrix (no templates). Nothing fancy but an easy place to start to at least start learning Object Oriented programming in C++ like any other. Well the thing is that I'm completely stumped with an error I'm getting. I've created a simple Win32 console app that links my FastMath.dll and uses the FMatrix class defined inside. Test app code is as simple as it can get, it only instantiates one FMatrix and then deletes it, and something that simple is giving me a runtime error. Here's the code in the tesp app:
#include "stdafx.h" #include "FMatrix.h" using namespace FastMath; using namespace std; int _tmain(int argc, _TCHAR* argv[]) { FMatrix *a=new FMatrix(5); cout << "A is a [" << a->GetRowCount() << "x" << a->GetColumnCount() << "] matrix." << endl; delete a; return 0; }
Ok the error I'm getting is when executing "delete a". The error message is:Windows has triggered a breakpoint in Tester.exe.
This may be due to a corruption of the heap, and indicates a bug in Tester.exe or any of the DLLs it has loaded.
The output window may have more diagnostic informationIf I try to continue I get the same error once and then succesive Assertion Failed error messages: "Expression: _CrtIsValidHeapPointer(pUserData)" and if I ignore that I get a HEAP CORRUPTION DETECTED error message "CRT detected that the application wrote to memory after end of heap buffer." I really do not understand what I'm doing wrong in my FMatrix file. I'm including header and source files below: FMatrix.h
#ifdef FASTMATH_EXPORTS #define FASTMATH_API __declspec(dllexport) #else #define FASTMATH_API __declspec(dllimport) #endif #pragma once #include "StdAfx.h" namespace FastMath { class FASTMATH_API FMatrix { private: int rw,cl; double *val; FMatrix(void); FMatrix(unsigned int,bool); FMatrix(unsigned int,unsigned int,bool); void initMatrix(unsigned int,unsigned int,bool); void destroy(void); public: FMatrix(const FMatrix&); //copy constructor FMatrix(unsigned int); FMatrix(unsigned int,unsigned int); FMatrix(unsigned int,unsigned int,double
gumi_r@msn.com wrote:
"CRT detected that the application wrote to memory after end of heap buffer."
That means that you allocated a block of memory, but wrote past the end of the block.
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ");
-
gumi_r@msn.com wrote:
"CRT detected that the application wrote to memory after end of heap buffer."
That means that you allocated a block of memory, but wrote past the end of the block.
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ");
Hi Micheal, thanks for the input. I guessed that much myselft but the problem is that I'll be damned if I see where I wrote past the allocated memory. Only the constructor and destructor are running in my test app and I don't see anywhere in the running code where I could be writing past any alocated memory. I really dont understand what is wrong.
-
Hi all, well allthough I'm new to C++ I've done my share of development in more user friendly environments, mainly C#. Anyhow I want to learn C++ as mainly personal interest as my professional life will be focused primarly in .NET development whenever it is needed. To learn the basics of the language I'm starting with a real easy Math class that will initially implement a Matrix (no templates). Nothing fancy but an easy place to start to at least start learning Object Oriented programming in C++ like any other. Well the thing is that I'm completely stumped with an error I'm getting. I've created a simple Win32 console app that links my FastMath.dll and uses the FMatrix class defined inside. Test app code is as simple as it can get, it only instantiates one FMatrix and then deletes it, and something that simple is giving me a runtime error. Here's the code in the tesp app:
#include "stdafx.h" #include "FMatrix.h" using namespace FastMath; using namespace std; int _tmain(int argc, _TCHAR* argv[]) { FMatrix *a=new FMatrix(5); cout << "A is a [" << a->GetRowCount() << "x" << a->GetColumnCount() << "] matrix." << endl; delete a; return 0; }
Ok the error I'm getting is when executing "delete a". The error message is:Windows has triggered a breakpoint in Tester.exe.
This may be due to a corruption of the heap, and indicates a bug in Tester.exe or any of the DLLs it has loaded.
The output window may have more diagnostic informationIf I try to continue I get the same error once and then succesive Assertion Failed error messages: "Expression: _CrtIsValidHeapPointer(pUserData)" and if I ignore that I get a HEAP CORRUPTION DETECTED error message "CRT detected that the application wrote to memory after end of heap buffer." I really do not understand what I'm doing wrong in my FMatrix file. I'm including header and source files below: FMatrix.h
#ifdef FASTMATH_EXPORTS #define FASTMATH_API __declspec(dllexport) #else #define FASTMATH_API __declspec(dllimport) #endif #pragma once #include "StdAfx.h" namespace FastMath { class FASTMATH_API FMatrix { private: int rw,cl; double *val; FMatrix(void); FMatrix(unsigned int,bool); FMatrix(unsigned int,unsigned int,bool); void initMatrix(unsigned int,unsigned int,bool); void destroy(void); public: FMatrix(const FMatrix&); //copy constructor FMatrix(unsigned int); FMatrix(unsigned int,unsigned int); FMatrix(unsigned int,unsigned int,double
Hi, Have you tried to override the delete operator?;) Regards, Eli