override operator new within a file?

M

Mark P

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?
 
A

adrian.hawryluk

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
 
S

Sarath

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..
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top