override operator new within a file?

Discussion in 'C++' started by Mark P, Mar 6, 2007.

  1. Mark P

    Mark P Guest

    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?
     
    Mark P, Mar 6, 2007
    #1
    1. Advertising

  2. Mark P

    Guest

    On Mar 6, 4:41 pm, Mark P <>
    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
     
    , Mar 6, 2007
    #2
    1. Advertising

  3. Mark P

    Sarath Guest

    On Mar 7, 5:41 am, Mark P <>
    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..
     
    Sarath, Mar 7, 2007
    #3
  4. On 6 Mar, 21:41, Mark P <> 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
     
    =?iso-8859-1?q?Erik_Wikstr=F6m?=, Mar 7, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mathieu Malaterre

    override delete operator to set to NULL

    Mathieu Malaterre, Sep 11, 2004, in forum: C++
    Replies:
    3
    Views:
    3,023
    Daniel T.
    Sep 12, 2004
  2. Shark
    Replies:
    2
    Views:
    602
    Alf P. Steinbach
    Jan 13, 2006
  3. Pierric
    Replies:
    4
    Views:
    356
    Default User
    Aug 24, 2006
  4. Ed
    Replies:
    1
    Views:
    555
  5. xmllmx
    Replies:
    6
    Views:
    434
    xmllmx
    Feb 3, 2010
Loading...

Share This Page