Can new operator be used as macro?

Discussion in 'C++' started by JeanDean, Mar 2, 2007.

  1. JeanDean

    JeanDean Guest

    For some debugging purpose I want to use overloaded new instead of
    existing MyAlloc() in a huge code base.
    But below macro doesnt work.
    Is there any way to pass "size" to overloaded new ?


    #define MyAlloc(size) new(size, WORK_HEAD )

    overloaded new code is :
    void* operator new(size_t sz, int headType) {
    ..
    ..
    ..
    }
     
    JeanDean, Mar 2, 2007
    #1
    1. Advertising

  2. JeanDean wrote:
    > For some debugging purpose I want to use overloaded new instead of
    > existing MyAlloc() in a huge code base.
    > But below macro doesnt work.
    > Is there any way to pass "size" to overloaded new ?
    >
    >
    > #define MyAlloc(size) new(size, WORK_HEAD )
    >
    > overloaded new code is :
    > void* operator new(size_t sz, int headType) {
    > .
    > .
    > .
    > }
    >


    Use operator new (which is a different thing from the new operator), but
    why use a macro?

    inline void* MyAlloc(size_t size)
    {
    return ::eek:perator new(size, WORK_HEAD);
    }

    Look's OK to me, unless I'm misunderstanding you.

    john
     
    John Harrison, Mar 2, 2007
    #2
    1. Advertising

  3. JeanDean

    JeanDean Guest

    On Mar 2, 4:59 pm, John Harrison <> wrote:
    > JeanDean wrote:
    > > For some debugging purpose I want to use overloaded new instead of
    > > existing MyAlloc() in a huge code base.
    > > But below macro doesnt work.
    > > Is there any way to pass "size" to overloaded new ?

    >
    > > #define MyAlloc(size) new(size, WORK_HEAD )

    >
    > > overloaded new code is :
    > > void* operator new(size_t sz, int headType) {
    > > .
    > > .
    > > .
    > > }

    >
    > Use operator new (which is a different thing from the new operator), but
    > why use a macro?
    >
    > inline void* MyAlloc(size_t size)
    > {
    > return ::eek:perator new(size, WORK_HEAD);
    >
    > }
    >
    > Look's OK to me, unless I'm misunderstanding you.
    >
    > john


    Thanks a lot for the suggestion
     
    JeanDean, Mar 2, 2007
    #3
    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. Dead RAM
    Replies:
    20
    Views:
    1,132
    John Harrison
    Jul 14, 2004
  2. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    590
    Jack Klein
    Sep 21, 2003
  3. Patrick Kowalzick
    Replies:
    5
    Views:
    486
    Patrick Kowalzick
    Mar 14, 2006
  4. Casey Hawthorne
    Replies:
    1
    Views:
    728
    Arne Vajhøj
    Mar 18, 2009
  5. xmllmx
    Replies:
    6
    Views:
    428
    xmllmx
    Feb 3, 2010
Loading...

Share This Page