Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > override operator new within a file?

Reply
Thread Tools

override operator new within a file?

 
 
Mark P
Guest
Posts: n/a
 
      03-06-2007
A coworker asked me this. I gather he's trying to track down a memory
leak. Is is possible to override operator new (and delete) only within
a single file?
 
Reply With Quote
 
 
 
 
adrian.hawryluk@gmail.com
Guest
Posts: n/a
 
      03-06-2007
On Mar 6, 4:41 pm, Mark P <(E-Mail Removed)>
wrote:
> A coworker asked me this. I gather he's trying to track down a memory
> leak. Is is possible to override operator new (and delete) only within
> a single file?


I beleive so, but it requires doing something very specific at
linking. I think, that if you have several .o/.obj files, and you use
a linker, it will take the order and any functions that exist to the
left will be used on the right.

It's been a while since I've even thought about this so bare with me.

ld -o a.out <some other options and libs> a.o new.o b.o <and some more
options and libs>

Now a.o will use the original new, and b.o should use the new located
in new.o.

I appologiese if this is not entirly correct. Check the ld man/info
page for more (possibly more accurate) info.


Adrian

 
Reply With Quote
 
 
 
 
Sarath
Guest
Posts: n/a
 
      03-07-2007
On Mar 7, 5:41 am, Mark P <(E-Mail Removed)>
wrote:
> A coworker asked me this. I gather he's trying to track down a memory
> leak. Is is possible to override operator new (and delete) only within
> a single file?


If you are dealing with some large source code, it's better to use
some wellknown tools like Bounds Checker (Numega), Intel vTune
Performance analyser etc..

 
Reply With Quote
 
=?iso-8859-1?q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      03-07-2007
On 6 Mar, 21:41, Mark P <(E-Mail Removed)> wrote:
> A coworker asked me this. I gather he's trying to track down a memory
> leak. Is is possible to override operator new (and delete) only within
> a single file?


It's technically undefined behaviour but you could try
#define new something

--
Erik Wikström

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What are the key differences between operator new and operator new[]? xmllmx C++ 6 02-03-2010 04:11 PM
Override operator new. Class-Based or Global Overridden Ed C++ 1 03-09-2009 11:36 AM
how to use the origin new operator after override it Pierric C++ 4 08-24-2006 05:29 PM
operator new override/overload? Shark C++ 2 01-13-2006 08:32 AM
override delete operator to set to NULL Mathieu Malaterre C++ 3 09-12-2004 01:43 AM



Advertisments