Redefining new

Discussion in 'C++' started by notme, Mar 26, 2005.

  1. notme

    notme Guest

    I have code with lots of "new int..." etc..
    I'd like to replace every instance with "new(allocInfo) int" (that is, using
    placement new)

    I tried doing:
    #define new (new(allocInfo))

    but that doesn't work... any hints?
    Thanks!
    notme, Mar 26, 2005
    #1
    1. Advertising

  2. notme

    Phlip Guest

    notme wrote:

    > I have code with lots of "new int..." etc..


    Why?

    > I'd like to replace every instance with "new(allocInfo) int" (that is,

    using
    > placement new)
    >
    > I tried doing:
    > #define new (new(allocInfo))


    If you actually need a "new int...", why does it appear in so many places
    that it's hard to upgrade?

    Are all those "new int..." things appearing in similar code that could be
    refactored together?

    More important: Can't those objects appear on your stack? Why the heap
    abuse?

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
    Phlip, Mar 26, 2005
    #2
    1. Advertising

  3. notme

    notme Guest

    >> I have code with lots of "new int..." etc..
    >
    > Why?


    Well, it was just an example. You should take the "etc" as "new Object",
    that
    is, allocating (some of the quite big) objects in the heap.

    >> I'd like to replace every instance with "new(allocInfo) int" (that is,

    > using
    >> placement new)
    >>
    >> I tried doing:
    >> #define new (new(allocInfo))

    >
    > If you actually need a "new int...", why does it appear in so many places
    > that it's hard to upgrade?


    Don't know, but that's not the point (the code isn't mine, I'm just making a
    port)

    > Are all those "new int..." things appearing in similar code that could be
    > refactored together?


    Unfortunately not.

    > More important: Can't those objects appear on your stack? Why the heap
    > abuse?


    So, is it possible?

    Regards,
    David.-
    notme, Mar 26, 2005
    #3
  4. notme

    Phlip Guest

    notme wrote:

    > So, is it possible?


    MFC modules always say this:

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    Hence, DEBUG_NEW looks a little bit like this:

    #define DEBUG_NEW new(THIS_FILE, __LINE__)



    Note that redefining a keyword is legal, after you #include your C++
    standard library headers...


    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
    Phlip, Mar 26, 2005
    #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. Nick Bassiliades

    Redefining an enumerated attribute type

    Nick Bassiliades, Dec 9, 2005, in forum: XML
    Replies:
    1
    Views:
    425
    Henry S. Thompson
    Dec 12, 2005
  2. uli
    Replies:
    5
    Views:
    4,806
    Dietmar Kuehl
    Apr 21, 2004
  3. Xiangliang Meng
    Replies:
    1
    Views:
    1,570
    Victor Bazarov
    Jun 21, 2004
  4. bberu
    Replies:
    7
    Views:
    618
    Ivan Vecerina
    Dec 18, 2004
  5. bberu
    Replies:
    1
    Views:
    713
    Ivan Vecerina
    Dec 17, 2004
Loading...

Share This Page