473,800 Members | 2,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4966

"hamidi" <ha****@yahoo.c om> wrote in message
news:85******** *************** ***@posting.goo gle.com...
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
433
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 bunch of people said what if exception occurs buffered stream is not closed. My Argument is over advantages of using 'Using' keyword. First Advantage being -- Using used for Dispose (Deterministic
2
5947
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 X509Certificate ( *.cer file ) so that it can be used to email as attachment. The real part is Encrypting using X509Certificate and CryptoServiceProvider.
1
567
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 want to use a callback from the client side to update webcontrols based on user input without using postback. I am seeking a way to stop the compile errors. using System; using System.Data;
4
642
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 code says, if I employ the using directive, I'm ok. /* built with Visual C++ 6, SP 5 */ namespace Traffic { enum Light { red, yellow, green }; }
10
2663
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 | don't, I need to know. Flames welcome.
17
3523
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 using std::cin; using std::cout;
2
2916
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 <string> header file and also will have to say using namespace std to make the string class visible. qn)how do i resolve the requirement of *not* using the "using" directive in the header file and at the same time declare my structure in the...
0
1206
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 <string.h> #include <math.h> #include <stdio.h> #include "stdafx.h"
1
2387
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 "IRIBIO_API_TEST.h" #include "IRIBIO_API_TESTDlg.h"
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10501
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10273
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7574
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.