Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. wierd delete [ ] myClass exception. Need Help PLZ! [modified]

wierd delete [ ] myClass exception. Need Help PLZ! [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++wpfdebugging
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gumi_r msn com
    wrote on last edited by
    #1

    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 information

    If 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
    
    M E 2 Replies Last reply
    0
    • G gumi_r msn com

      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 information

      If 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
      
      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      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");

      G 1 Reply Last reply
      0
      • M Michael Dunn

        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");

        G Offline
        G Offline
        gumi_r msn com
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • G gumi_r msn com

          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 information

          If 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
          
          E Offline
          E Offline
          eli15021979
          wrote on last edited by
          #4

          Hi, Have you tried to override the delete operator?;) Regards, Eli

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups