473,320 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

821206 - using DEBUG_NEW

hi all
this is the whole of my program:

#include "stdafx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

void main()
{
char *p=new char[10];
delete[] p;
}

i'm using visual studio .net
when i trace the flow of the program i see that the following override
of operator new in afxmem.cpp is called:

Ln 68: void* __cdecl operator new[](size_t nSize, LPCSTR lpszFileName,
int nLine)

i expect the overriden operator delete[] with the appropriate
prototype is called, that is:

Ln 83: void __cdecl operator delete[](void* pData, LPCSTR /*
lpszFileName */,
int /* nLine */)

but this is not the case. instead, the following operator delete[] is
called:

Ln 377: void __cdecl operator delete[](void* p)

why?
Jul 22 '05 #1
2 4922

"hamidi" <ha****@yahoo.com> wrote in message
news:85**************************@posting.google.c om...
hi all
this is the whole of my program:

#include "stdafx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

void main()
{
char *p=new char[10];
delete[] p;
}

i'm using visual studio .net
when i trace the flow of the program i see that the following override
of operator new in afxmem.cpp is called:

Ln 68: void* __cdecl operator new[](size_t nSize, LPCSTR lpszFileName,
int nLine)

i expect the overriden operator delete[] with the appropriate
prototype is called, that is:

Ln 83: void __cdecl operator delete[](void* pData, LPCSTR /*
lpszFileName */,
int /* nLine */)

but this is not the case. instead, the following operator delete[] is
called:

Ln 377: void __cdecl operator delete[](void* p)

why?


Why not? There is no requirement for new and delete to have matching
argument types. And how could the compiler know that the delete you expect
to be called should be called? One delete looks exactly the same as another.

john
Jul 22 '05 #2
hamidi wrote:

hi all
this is the whole of my program:

#include "stdafx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

void main()
{
char *p=new char[10];
delete[] p;
}

i'm using visual studio .net
when i trace the flow of the program i see that the following override
of operator new in afxmem.cpp is called:

Ln 68: void* __cdecl operator new[](size_t nSize, LPCSTR lpszFileName,
int nLine)

i expect the overriden operator delete[] with the appropriate
prototype is called, that is:

Ln 83: void __cdecl operator delete[](void* pData, LPCSTR /*
lpszFileName */,
int /* nLine */)

but this is not the case. instead, the following operator delete[] is
called:

Ln 377: void __cdecl operator delete[](void* p)

why?


Why not?
The additional arguments in the new operator are used to track
memory allocations and where in your source they have happend.
A table is built which stores the memory address, the filename
and the linenumber. When a delete[] is done the corresponding entry
is removed from that table, so when the program finally exits, this
table theoretically should be empty. If it is not, the system can
tell you: "You made a memory allocation in file xxx at line yyy.
This memory has never been deleted".
So what could your form of delete[] tell the system what it doesn't
already know?

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mehul Patel | last post by:
Our .Net team have been pondering about using keyword. We are using streams FileStream and BufferedStream. We use using keyword at FileStream, and not BufferedStream which wraps FileStream. So...
2
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
1
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
4
by: Marshall Mills | last post by:
As I understand it, loaded statement, a using declaration should be all I need to see an enum from within a namespace. The below code works fine with class, struct, and union. What gives? As the...
10
by: Christopher Benson-Manica | last post by:
Why can't I use a class destructor in a using declaration: using MyClass::~MyClass; ? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
2
by: trying_to_learn | last post by:
im in the primary stages of learning C++. The book im learning from says Dont use using namespace.. directive in header file However im trying to make the following header file.I need to include...
0
by: D Steward | last post by:
I am attempting to build a dll from some functions that were written in C, but I am running into some compiler errors. I am writting code in the dll as follows: #include <stdlib.h> #include...
1
by: masoud taheri | last post by:
can some one tell how can convert this class to c# class or convert it to dll for using in c# app // FTDI_loadDlg.cpp : ±¸اِ ئؤہد // #include "dos.h" #include "stdafx.h" #include...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.