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

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

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

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,522
    John Harrison
    Jul 14, 2004
  2. Replies:
    4
    Views:
    345
    Eric Pruneau
    Nov 9, 2005
  3. Patrick Kowalzick
    Replies:
    5
    Views:
    707
    Patrick Kowalzick
    Mar 14, 2006
  4. mfactor
    Replies:
    1
    Views:
    405
    joseph cook
    Jul 12, 2008
  5. Casey Hawthorne
    Replies:
    1
    Views:
    899
    Arne Vajhøj
    Mar 18, 2009
  6. xmllmx
    Replies:
    6
    Views:
    618
    xmllmx
    Feb 3, 2010
  7. Ted Byers
    Replies:
    23
    Views:
    724
    Peter J. Holzer
    Nov 15, 2008
  8. Replies:
    2
    Views:
    768
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...