Click here to Skip to main content
15,920,217 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionnew operator Pin
Ali Tavakol26-Aug-05 3:35
Ali Tavakol26-Aug-05 3:35 
AnswerRe: new operator Pin
Chris Losinger26-Aug-05 3:57
professionalChris Losinger26-Aug-05 3:57 
AnswerRe: new operator Pin
namaskaaram26-Aug-05 4:01
namaskaaram26-Aug-05 4:01 
AnswerRe: new operator Pin
Emilio Garavaglia26-Aug-05 4:12
Emilio Garavaglia26-Aug-05 4:12 
GeneralRe: new operator Pin
toxcct26-Aug-05 4:20
toxcct26-Aug-05 4:20 
GeneralRe: new operator Pin
Tim Smith26-Aug-05 6:06
Tim Smith26-Aug-05 6:06 
GeneralRe: new operator Pin
John R. Shaw27-Aug-05 12:02
John R. Shaw27-Aug-05 12:02 
GeneralRe: new operator Pin
Emilio Garavaglia28-Aug-05 20:48
Emilio Garavaglia28-Aug-05 20:48 
Yes, but _nh_malloc is an internal CRT function that call other internal functions.

Here's the call stack for a
int main() { delete new int(0); return 0; }

n1.exe!_heap_alloc_base(size=40) 
n1.exe!_heap_alloc_dbg(nSize=4, nBlockUse=1, szFileName=0x00000000, nLine=0) n1.exe!_nh_malloc_dbg(nSize=4, nhFlag=1, nBlockUse=1, szFileName=0x00000000, nLine=0)
n1.exe!_nh_malloc(nSize=4, nhFlag=1)
n1.exe!operator new(cb=4) 
n1.exe!main() 
n1.exe!mainCRTStartup()
KERNEL32.DLL!796d893d() 	

and here's _heap_alloc_base next instruction

        ...
        ...
-->     return <code>HeapAlloc</code>(_crtheap, 0, size);
}


Similarly, operator delete calls HeapFree.

The same program, after redefining new and delete as
void* operator new(size_t s)
{	return malloc(s); }

void operator delete(void* p)
{	free(p); }

drive towards the same _heap_aloc_dbg call.




2 bugs found.
> recompile ...
65534 bugs found.
D'Oh! | :doh:

GeneralRe: new operator Pin
John R. Shaw28-Aug-05 22:35
John R. Shaw28-Aug-05 22:35 
AnswerRe: new operator Pin
David Crow26-Aug-05 4:15
David Crow26-Aug-05 4:15 
GeneralRe: new operator Pin
Emilio Garavaglia28-Aug-05 21:01
Emilio Garavaglia28-Aug-05 21:01 
QuestionDate receiver Pin
Ali Tavakol26-Aug-05 3:27
Ali Tavakol26-Aug-05 3:27 
AnswerRe: Date receiver Pin
David Crow26-Aug-05 3:30
David Crow26-Aug-05 3:30 
GeneralRe: Date receiver Pin
Ali Tavakol26-Aug-05 3:41
Ali Tavakol26-Aug-05 3:41 
GeneralRe: Date receiver Pin
David Crow26-Aug-05 3:55
David Crow26-Aug-05 3:55 
GeneralRe: Date receiver Pin
Maximilien26-Aug-05 4:13
Maximilien26-Aug-05 4:13 
Questioncaling conventions Pin
Member 222581226-Aug-05 1:29
Member 222581226-Aug-05 1:29 
AnswerRe: caling conventions Pin
Cedric Moonen26-Aug-05 1:55
Cedric Moonen26-Aug-05 1:55 
GeneralRe: caling conventions Pin
toxcct26-Aug-05 2:26
toxcct26-Aug-05 2:26 
GeneralRe: caling conventions Pin
Cedric Moonen26-Aug-05 2:36
Cedric Moonen26-Aug-05 2:36 
GeneralRe: caling conventions Pin
Member 222581226-Aug-05 3:00
Member 222581226-Aug-05 3:00 
GeneralRe: caling conventions Pin
MailtoGops26-Aug-05 3:19
MailtoGops26-Aug-05 3:19 
GeneralRe: caling conventions Pin
David Crow26-Aug-05 3:22
David Crow26-Aug-05 3:22 
QuestionHow to get HWND of my application window ? Pin
Amarelia26-Aug-05 1:08
Amarelia26-Aug-05 1:08 
AnswerRe: How to get HWND of my application window ? Pin
Jack Puppy26-Aug-05 1:41
Jack Puppy26-Aug-05 1:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.