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. Tracking Memory Allocations

Tracking Memory Allocations

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminperformance
12 Posts 5 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.
  • T Offline
    T Offline
    The_Server
    wrote on last edited by
    #1

    :cool:HI ALL:cool: I want that every memory allocation will be tracked... is there a way for me to overwrite the new and delete functions... this and every other solution will be appreciated gracefully. Objective: Tracking Memory Allocations Thank you all... :rose: -==--==--==--==--==--==- =--= The Server =--= -==--==--==--==--==--==-

    V A 2 Replies Last reply
    0
    • T The_Server

      :cool:HI ALL:cool: I want that every memory allocation will be tracked... is there a way for me to overwrite the new and delete functions... this and every other solution will be appreciated gracefully. Objective: Tracking Memory Allocations Thank you all... :rose: -==--==--==--==--==--==- =--= The Server =--= -==--==--==--==--==--==-

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      The_Server wrote: is there a way for me to overwrite the new and delete functions... I'm assuming you meant to say overload , because new and delete are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. [EDIT]Red alert! Red alert! I made a horrifying mistake. Both new and delete can be overloaded. See all posts below.[/EDIT] Regards,
      Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design.

      N P 2 Replies Last reply
      0
      • V Vikram A Punathambekar

        The_Server wrote: is there a way for me to overwrite the new and delete functions... I'm assuming you meant to say overload , because new and delete are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. [EDIT]Red alert! Red alert! I made a horrifying mistake. Both new and delete can be overloaded. See all posts below.[/EDIT] Regards,
        Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design.

        N Offline
        N Offline
        Neville Franks
        wrote on last edited by
        #3

        Vikram Punathambekar wrote: I'm assuming you meant to say overload , because new and delete are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. Vikram, I'm afraid you aren't right. The new operator calls a function to allocate memory and you can overload or rewrite that. There is also "placement new". Look up a good C++ reference for more info. "More Effectiver C++" covers this briefly. And there maybe articles here on CP about overloading new and delete if my memory serves me correctly. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

        V 2 Replies Last reply
        0
        • T The_Server

          :cool:HI ALL:cool: I want that every memory allocation will be tracked... is there a way for me to overwrite the new and delete functions... this and every other solution will be appreciated gracefully. Objective: Tracking Memory Allocations Thank you all... :rose: -==--==--==--==--==--==- =--= The Server =--= -==--==--==--==--==--==-

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          The C Runtime library provides memory tracking capabilities. See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/_core_solving_buffer_overwrites_and_memory_leaks.asp[^] If you just want to find memory leaks that should do the trick. See my reply to Vikram re/ overloading new/delete.

          1 Reply Last reply
          0
          • V Vikram A Punathambekar

            The_Server wrote: is there a way for me to overwrite the new and delete functions... I'm assuming you meant to say overload , because new and delete are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. [EDIT]Red alert! Red alert! I made a horrifying mistake. Both new and delete can be overloaded. See all posts below.[/EDIT] Regards,
            Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design.

            P Offline
            P Offline
            pankajdaga
            wrote on last edited by
            #5

            Hi, Both new and delete can be overloaded. Also, after overloading, you can still call the global new by ::new() Pankaj Without struggle, there is no progress

            V T 3 Replies Last reply
            0
            • N Neville Franks

              Vikram Punathambekar wrote: I'm assuming you meant to say overload , because new and delete are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. Vikram, I'm afraid you aren't right. The new operator calls a function to allocate memory and you can overload or rewrite that. There is also "placement new". Look up a good C++ reference for more info. "More Effectiver C++" covers this briefly. And there maybe articles here on CP about overloading new and delete if my memory serves me correctly. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

              V Offline
              V Offline
              Vikram A Punathambekar
              wrote on last edited by
              #6

              Neville Franks wrote: Vikram, I'm afraid you aren't right. Yes, I'm afraid you're right. Punning apart, thanks for correcting me. Yes, new can be overloaded and so can delete.In fact, I guess even calls like

              int *p=new int[10];

              and

              foo *ptr=new foo;

              can be considered overloading, right? I wasn't drinking. I feel so dumb :-O ...I wonder if learning VB is any fun?
              Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design.

              1 Reply Last reply
              0
              • P pankajdaga

                Hi, Both new and delete can be overloaded. Also, after overloading, you can still call the global new by ::new() Pankaj Without struggle, there is no progress

                V Offline
                V Offline
                Vikram A Punathambekar
                wrote on last edited by
                #7

                Yes, I made a mistake :-O . I don't even know what I confused it with. See my earlier post. Thanx for pointing it out.
                Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design.

                1 Reply Last reply
                0
                • N Neville Franks

                  Vikram Punathambekar wrote: I'm assuming you meant to say overload , because new and delete are not functions; they are operators. In that case, no- these operators CANNOT be overloaded. Vikram, I'm afraid you aren't right. The new operator calls a function to allocate memory and you can overload or rewrite that. There is also "placement new". Look up a good C++ reference for more info. "More Effectiver C++" covers this briefly. And there maybe articles here on CP about overloading new and delete if my memory serves me correctly. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

                  V Offline
                  V Offline
                  Vikram A Punathambekar
                  wrote on last edited by
                  #8

                  I thought this warranted a second reply- new is an operator, isn't it? It calls a function alright, just like you have to define a function when you're overloading the + operator for, say, a Complex class. But that doesn't mean + becomes a function, even w.r.t. class Complex :~ And yeah, my 5 for pointing it out. :) Thanks,
                  Vikram. ----------------------------- My site due for a massive update 1. Don't ask unnecessary questions. You know what I mean? 2. Avoid redundancy at all costs. 3. Avoid redundancy at all costs. "Do not give redundant error messages again and again." - A classmate of mine, while giving a class talk on error detection in compiler design.

                  1 Reply Last reply
                  0
                  • P pankajdaga

                    Hi, Both new and delete can be overloaded. Also, after overloading, you can still call the global new by ::new() Pankaj Without struggle, there is no progress

                    T Offline
                    T Offline
                    The_Server
                    wrote on last edited by
                    #9

                    1st of all: I want to thank all of you for your interest... 2nd: How can I overload the new and delete functions? :confused: Thank you all :rose:The Server:rose:

                    1 Reply Last reply
                    0
                    • P pankajdaga

                      Hi, Both new and delete can be overloaded. Also, after overloading, you can still call the global new by ::new() Pankaj Without struggle, there is no progress

                      T Offline
                      T Offline
                      The_Server
                      wrote on last edited by
                      #10

                      1st of all: I want to thank all of you for your interest... 2nd: How can I overload the new and delete functions? :confused: Thank you all The Server :rose:

                      P 1 Reply Last reply
                      0
                      • T The_Server

                        1st of all: I want to thank all of you for your interest... 2nd: How can I overload the new and delete functions? :confused: Thank you all The Server :rose:

                        P Offline
                        P Offline
                        pankajdaga
                        wrote on last edited by
                        #11

                        You an overload class specific new and delete as: void * operator new (size_t size) { // do your thing } void operator delete (void * mem) { if (mem) // do yout thing } You can also overload the global new and delete. Example, you can define something like: void * operator new (size_t size, char * fileName); void operator delete (void * p, char * fileName); Pankaj Without struggle, there is no progress

                        T 1 Reply Last reply
                        0
                        • P pankajdaga

                          You an overload class specific new and delete as: void * operator new (size_t size) { // do your thing } void operator delete (void * mem) { if (mem) // do yout thing } You can also overload the global new and delete. Example, you can define something like: void * operator new (size_t size, char * fileName); void operator delete (void * p, char * fileName); Pankaj Without struggle, there is no progress

                          T Offline
                          T Offline
                          The_Server
                          wrote on last edited by
                          #12

                          Dear Pankaj and every one that reads this message Thank you :rose: ... Only one question that which the most disturbing How do I call the Object's constructor(if is object?) =-=-=-=--=-=-=-=-= :rose: The Server =-=-=-=--=-=-=-=-=

                          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