Is there any way to disable global operator new?

Discussion in 'C++' started by google@pedriana.com, Nov 16, 2008.

  1. Guest

    We need to be able to disable global operator new at compile time. We
    are developing a large library and need to control all memory
    allocation and cannot have a mistake whereby a mistaken use of global
    operator new creeps in. It is not feasible to solve this via
    implementing our own global operator new which asserts(false), as
    there is no practical way to test all paths of execution. This is a
    large and complex library, to say the least. In fact there's a chance
    you are using it to read this message. :)

    Due to the design of C++ and its special/unusual treatment of new/
    delete, I can think of no way to accomplish this, nor can I think of
    an alternative means to accomplish what we need. #defining new away
    doesn't work because placement new and class new still need to work.
    , Nov 16, 2008
    #1
    1. Advertising

  2. wrote:
    > We need to be able to disable global operator new at compile time. We
    > are developing a large library and need to control all memory
    > allocation and cannot have a mistake whereby a mistaken use of global
    > operator new creeps in. It is not feasible to solve this via
    > implementing our own global operator new which asserts(false), as


    Patch a you standard library for testing purposes and remove the global
    operator new. You will get a linkage error in case you are calling new
    from some point.
    But I think that the standard library itself requires this operator. So
    you might get some additional errors from there.

    > there is no practical way to test all paths of execution. This is a
    > large and complex library, to say the least. In fact there's a chance
    > you are using it to read this message. :)


    While this is not uncommon, you may run into other troubles anyway.


    > Due to the design of C++ and its special/unusual treatment of new/
    > delete, I can think of no way to accomplish this, nor can I think of
    > an alternative means to accomplish what we need. #defining new away
    > doesn't work because placement new and class new still need to work.


    I wonder why it is not possible to replace the global operators in a way
    that they have a meaningful implementation of your memory management.

    Otherwise you might derive all your base classes from a helper class
    that overloads new and delete. Of course, this will not work for PODs.
    Marcel Müller, Nov 16, 2008
    #2
    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. John Holmes

    Is there a way to disable auto-formatting

    John Holmes, Apr 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    350
    Steven Cheng[MSFT]
    Apr 10, 2004
  2. Dodo
    Replies:
    1
    Views:
    353
    Ron Natalie
    Aug 26, 2003
  3. xmllmx
    Replies:
    6
    Views:
    398
    xmllmx
    Feb 3, 2010
  4. pluskid
    Replies:
    6
    Views:
    88
    Christophe Mckeon
    Dec 14, 2007
  5. Andries

    is there a way ..... any way

    Andries, Apr 26, 2004, in forum: Perl Misc
    Replies:
    27
    Views:
    235
    Robin
    Apr 27, 2004
Loading...

Share This Page