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. overhead of NEW and DELETE

overhead of NEW and DELETE

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
6 Posts 6 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.
  • G Offline
    G Offline
    ginjikun
    wrote on last edited by
    #1

    Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)

    enhzflepE K D T M 5 Replies Last reply
    0
    • G ginjikun

      Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)

      K Offline
      K Offline
      kDevloper
      wrote on last edited by
      #2

      I dont think there will be any performance issue.

      1 Reply Last reply
      0
      • G ginjikun

        Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)

        enhzflepE Offline
        enhzflepE Offline
        enhzflep
        wrote on last edited by
        #3

        PSEUDOCODE

        int *varArray[1000000];

        StartNewTime = getSystemTimer();

        for (i=0; i<1000000; i++)
        varArray[i] = new int;

        StartDelTime = getSystemTimer();

        for (i=0; i<1000000; i++)
        delete varArray[i];

        endTime = getSystemTimer();

        elapsedNewTime = StartDelTime - StartNewTime;
        elapsedDelTime = endTime - StartDelTime;

        timePerNew = (float) elapsedNewTime / 1000000.0;
        timePerDel = (float) elapsedDelTime / 1000000.0;

        Of course, if they were C++ objects that were calling constuctors & destructors, then the answer would be different, and you would need to have an array of 1000000 (or whatever other arbitrary number suits you) pointers to objects of the type to be investigated. Just remember - if 1 event is too quick to time effectively, then just time a whole heap of them at once.

        1 Reply Last reply
        0
        • G ginjikun

          Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Anytime you employ the use of Windows' memory manager, there will be some overhead involved. It may be negligible, but there will be some. Is it really part of your design to allocate and release memory every second?

          "Love people and use things, not love things and use people." - Unknown

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          1 Reply Last reply
          0
          • G ginjikun

            Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            ginjikun wrote:

            I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second?

            could it don't by allocating static memory, instead of using dynamic memory. yes there could be dynamic issue, as memory allocation itself is tedious task. how big is data??, could you code like this :- if( MEMORY_REQUIRED > STATIC_MEMORY_ALLOCATED) allocate DYNAMIC_MEMORY else use STATIC_MEMORY now you have choose STATIC_MEMORY_ALLOCATED limits according to you.

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
            Never mind - my own stupidity is the source of every "problem" - Mixture

            cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/xml>

            1 Reply Last reply
            0
            • G ginjikun

              Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)

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

              Every 1 second is not very often relative to how many operations can be done in one second by a modern PC. I can allocate/free hundreds of video frame buffers a second using barely any CPU. If your allocations are too slow (for reasons others have mentioned) then you can implement some kind of pre-allocated memory scheme. Mark

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

              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