Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Initializing a CMemFile derived class

Posted on 1998-11-05
2
Medium Priority
?
415 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
2 Comments
 
LVL 2

Accepted Solution

by:
jstolan earned 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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