Menu

Overidding new Operator Errors in 2.4.0?

Developer
Anonymous
2005-10-18
2013-05-20
  • Anonymous

    Anonymous - 2005-10-18

    I recently downloaded the latest version of TinyXML, and have encountered compile errors that I havn't had with previous versions (The last version I downloaded was around May time this year)

    I override the new operator with the following code

    #ifdef _DEBUG
    #define MARY_DEBUG_NEW  new(__FILE__, __LINE__)
    #else
    #define MARY_DEBUG_NEW  new
    #endif
    #define new                             MARY_DEBUG_NEW

    I then use the following overrides to allow for custom memory management.

    new(size_t size, const char *_file, int _line)   
    new[](size_t size, const char *_file, int _line)
    new(size_t size)                               
    new[](size_t size)                               

    Unfortunatly, I know have a problem in tinystr.h, line 220 (rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));)

    Due to the new operator taking a size param, it throws my memeory management functions out of the window, and cannot find a suitable function to call.

    Are you aware of a solution for this?

    Thanks

     
    • Ellers

      Ellers - 2005-10-18

      Its not clean but why not change the new() on line 220 to something like new_1, then #define new_1 to be your debug version but with the extra parameter?

       
    • Anonymous

      Anonymous - 2005-10-18

      That was one idea I toyed with, but I went with the simpler option of including tinyxml.h before my new defines (which means they use the standard heap).

      This method compiles and works, but doesnt use my heap functions, which is the ideal, as it deals with more than just tracking memory leaks.

      Spree

       
    • Lee Thomason

      Lee Thomason - 2005-10-18

      That's a good catch and something I want to fix. (On some unusual systems structure aligment requirements could get confused as well.)

      On the other hand, the intent to only have one memory allocation is a good one.

      Hmm.

      Any other ideas on how to get this to work with one memory allocator but not confuse the overrides?

      lee

       
    • Lee Thomason

      Lee Thomason - 2005-10-18

      After additional thought, it might just be simplest to go with:

      rep_ = static_cast<Rep*>(new int[enough mem])

      The integer allocation should guarentee 32 bit alignment for platforms that care about that sort of thing, and it would allocate from the normal array allocator.

      The cast is no more safe, or unsafe, than the current one. Over-ridden new/delete should work again as expected.

      lee

       
    • Lee Thomason

      Lee Thomason - 2005-10-19

      This bug was troubling me. I just fixed 2.4.1 which fixes this bug and a CDATA output bug.

      lee

       
      • Anonymous

        Anonymous - 2005-10-19

        Excellent

        Any idea when this will be updated in the CVS server to I can download it and check how it goes?

         

Log in to post a comment.

MongoDB Logo MongoDB