Tracking Memory Allocations
-
The_Server wrote: is there a way for me to overwrite the new and delete functions... I'm assuming you meant to say overload , because
new
anddelete
are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. [EDIT]Red alert! Red alert! I made a horrifying mistake. Bothnew
anddelete
can be overloaded. See all posts below.[/EDIT] Regards,
Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design.Vikram Punathambekar wrote: I'm assuming you meant to say overload , because new and delete are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. Vikram, I'm afraid you aren't right. The new operator calls a function to allocate memory and you can overload or rewrite that. There is also "placement new". Look up a good C++ reference for more info. "More Effectiver C++" covers this briefly. And there maybe articles here on CP about overloading new and delete if my memory serves me correctly. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
-
:cool:HI ALL:cool: I want that every memory allocation will be tracked... is there a way for me to overwrite the
new
anddelete
functions... this and every other solution will be appreciated gracefully. Objective:Tracking Memory Allocations
Thank you all... :rose: -==--==--==--==--==--==- =--=The Server
=--= -==--==--==--==--==--==-The C Runtime library provides memory tracking capabilities. See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/_core_solving_buffer_overwrites_and_memory_leaks.asp[^] If you just want to find memory leaks that should do the trick. See my reply to Vikram re/ overloading new/delete.
-
The_Server wrote: is there a way for me to overwrite the new and delete functions... I'm assuming you meant to say overload , because
new
anddelete
are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. [EDIT]Red alert! Red alert! I made a horrifying mistake. Bothnew
anddelete
can be overloaded. See all posts below.[/EDIT] Regards,
Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design.Hi, Both new and delete can be overloaded. Also, after overloading, you can still call the global new by ::new() Pankaj Without struggle, there is no progress
-
Vikram Punathambekar wrote: I'm assuming you meant to say overload , because new and delete are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. Vikram, I'm afraid you aren't right. The new operator calls a function to allocate memory and you can overload or rewrite that. There is also "placement new". Look up a good C++ reference for more info. "More Effectiver C++" covers this briefly. And there maybe articles here on CP about overloading new and delete if my memory serves me correctly. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
Neville Franks wrote: Vikram, I'm afraid you aren't right. Yes, I'm afraid you're right. Punning apart, thanks for correcting me. Yes,
new
can be overloaded and so candelete
.In fact, I guess even calls likeint *p=new int[10];
and
foo *ptr=new foo;
can be considered overloading, right? I wasn't drinking. I feel so dumb :-O ...I wonder if learning VB is any fun?
Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design. -
Hi, Both new and delete can be overloaded. Also, after overloading, you can still call the global new by ::new() Pankaj Without struggle, there is no progress
Yes, I made a mistake :-O . I don't even know what I confused it with. See my earlier post. Thanx for pointing it out.
Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design. -
Vikram Punathambekar wrote: I'm assuming you meant to say overload , because new and delete are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. Vikram, I'm afraid you aren't right. The new operator calls a function to allocate memory and you can overload or rewrite that. There is also "placement new". Look up a good C++ reference for more info. "More Effectiver C++" covers this briefly. And there maybe articles here on CP about overloading new and delete if my memory serves me correctly. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
I thought this warranted a second reply- new is an operator, isn't it? It calls a function alright, just like you have to define a function when you're overloading the
+
operator for, say, aComplex
class. But that doesn't mean+
becomes a function, even w.r.t. classComplex
:~ And yeah, my 5 for pointing it out. :) Thanks,
Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design. -
Hi, Both new and delete can be overloaded. Also, after overloading, you can still call the global new by ::new() Pankaj Without struggle, there is no progress
1st of all: I want to thank all of you for your interest... 2nd: How can I overload the
new
anddelete
functions? :confused: Thank you all :rose:The Server:rose: -
Hi, Both new and delete can be overloaded. Also, after overloading, you can still call the global new by ::new() Pankaj Without struggle, there is no progress
1st of all: I want to thank all of you for your interest... 2nd: How can I overload the
new
anddelete
functions? :confused: Thank you all The Server :rose: -
1st of all: I want to thank all of you for your interest... 2nd: How can I overload the
new
anddelete
functions? :confused: Thank you all The Server :rose:You an overload class specific new and delete as: void * operator new (size_t size) { // do your thing } void operator delete (void * mem) { if (mem) // do yout thing } You can also overload the global new and delete. Example, you can define something like: void * operator new (size_t size, char * fileName); void operator delete (void * p, char * fileName); Pankaj Without struggle, there is no progress
-
You an overload class specific new and delete as: void * operator new (size_t size) { // do your thing } void operator delete (void * mem) { if (mem) // do yout thing } You can also overload the global new and delete. Example, you can define something like: void * operator new (size_t size, char * fileName); void operator delete (void * p, char * fileName); Pankaj Without struggle, there is no progress
Dear Pankaj and every one that reads this message
Thank you :rose: ... Only one question that which the most disturbing How do I call the Object's constructor(if is object?) =-=-=-=--=-=-=-=-= :rose: The Server =-=-=-=--=-=-=-=-=