Solved

Initializing a CMemFile derived class

Posted on 1998-11-05
2
387 Views
Last Modified: 2013-11-20
To work on a file i have derived one class from CMemFile.
Then the idea is to load the memory with the file (its working fine)
the problem is that everytime i end the application this appears in the output window:
"
Detected memory leaks!
Dumping objects ->
{56} normal block at 0x00674260, 1000 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
"

here how i am creating my class CIntelHexaFile

BYTE *pBuf = (BYTE*) new BYTE(10000);
m_HexaMem  = (CIntelHexaFile*) new CIntelHexaFile(pBuf,10000,5000);

this is done in other object constructor. In the destructor i do :
delete m_HexaMem;

m_HexaMem is declared as CIntelHexaFile * m_HexaMem.


Can anyone tell me what is the problem?
(pBuf is destructed be the CMemFile destructor.Right?)
0
Comment
Question by:jmartins71
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
jstolan earned 50 total points
ID: 1324254
pBuf will only be destroyed if the CMemFile m_bAutoDelete member variable is TRUE.  When you create the class with the constructor you have chosen, m_bAutodelete initializes to FALSE.

Since you are creating the buffer, it's probably cleaner for you to delete it explicitly.  For the record, here is the destructor of CMemFile:

CMemFile::~CMemFile()
{
      // Close should have already been called, but we check anyway
      if (m_lpBuffer)
            Close();
      ASSERT(m_lpBuffer == NULL);

      m_nGrowBytes = 0;
      m_nPosition = 0;
      m_nBufferSize = 0;
      m_nFileSize = 0;
}

And here is the close function it calls:

void CMemFile::Close()
{
      ASSERT_VALID(this);

      m_nGrowBytes = 0;
      m_nPosition = 0;
      m_nBufferSize = 0;
      m_nFileSize = 0;
      if (m_lpBuffer && m_bAutoDelete)
            Free(m_lpBuffer);
      m_lpBuffer = NULL;
}


0
 

Author Comment

by:jmartins71
ID: 1324255
thanks jstolan.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 99
Macro to save highlighted rows as a separate file 5 51
fizzArray2 challenge 1 111
noX challenge 17 144
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question