Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. global new operator issue

global new operator issue

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abyss
    wrote on last edited by
    #1

    I'm trying to override the global new operator:

    void* __cdecl ::operator new(size_t nSize)
    {
    ...
    }

    It is called for almost all cases. However in case of std::string allocation it does not work. The internal allocator of the std::string object still calls the default (CRT) global new allocator. Any idea why? Thanks, Abyss

    C 1 Reply Last reply
    0
    • A Abyss

      I'm trying to override the global new operator:

      void* __cdecl ::operator new(size_t nSize)
      {
      ...
      }

      It is called for almost all cases. However in case of std::string allocation it does not work. The internal allocator of the std::string object still calls the default (CRT) global new allocator. Any idea why? Thanks, Abyss

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Maybe the STL authors want to control the allocation process just as you are trying to do. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      A 1 Reply Last reply
      0
      • C CPallini

        Maybe the STL authors want to control the allocation process just as you are trying to do. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        A Offline
        A Offline
        Abyss
        wrote on last edited by
        #3

        Not sure, because for std::vector my new operator is called. And in some cases for the std::string too. In the particular case the given std::string calls my new operator, however my delete operator is not called. This of course is toxic, because the default CRT delete tries to release my pointer and the application crashes. My delete operator is defined as: void __cdecl ::operator delete(void* ptr) { ... } Not sure what is wrong here... Thanks, Abyss

        M 1 Reply Last reply
        0
        • A Abyss

          Not sure, because for std::vector my new operator is called. And in some cases for the std::string too. In the particular case the given std::string calls my new operator, however my delete operator is not called. This of course is toxic, because the default CRT delete tries to release my pointer and the application crashes. My delete operator is defined as: void __cdecl ::operator delete(void* ptr) { ... } Not sure what is wrong here... Thanks, Abyss

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          You do know you have the ultimate documentation, don't you? :) (That would be the source code)

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          B A 2 Replies Last reply
          0
          • M Mark Salsbery

            You do know you have the ultimate documentation, don't you? :) (That would be the source code)

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            B Offline
            B Offline
            Bram van Kampen
            wrote on last edited by
            #5

            :)

            Bram van Kampen

            1 Reply Last reply
            0
            • M Mark Salsbery

              You do know you have the ultimate documentation, don't you? :) (That would be the source code)

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              A Offline
              A Offline
              Abyss
              wrote on last edited by
              #6

              Not sure I understand...

              B 1 Reply Last reply
              0
              • A Abyss

                Not sure I understand...

                B Offline
                B Offline
                Bram van Kampen
                wrote on last edited by
                #7

                It means: You designed the Software, and You wrote the Code, so You are the best person in the world to know what's it supposed to do or not do in the firstplace. None of us are in that priviledged position. :)

                Bram van Kampen

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups