C++ program run time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MPI
    New Member
    • Nov 2007
    • 2

    C++ program run time

    Hi,

    I need to improve the run time of C++ program. I wish to know should I use "new" operator or "vector" for 2 dimensional dynamic arrays ? What are the other ways of reducing run time of the program? Are there any general tips?

    Thanks
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by MPI
    Hi,

    I need to improve the run time of C++ program. I wish to know should I use "new" operator or "vector" for 2 dimensional dynamic arrays ? What are the other ways of reducing run time of the program? Are there any general tips?

    Thanks

    Using arrays instead of dynamic allocation would be another idea to reduce the run-time.
    Raghuram

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Your question doesn't make sense. new is for synamic allocation and a vector is an array. It looks like apples and oranges to me.

      Run a profiler on your code and see where the holdups are. Blindly putting code on the off-chance it will run faster is a waste of time. Especially since one solution is a faster machine or one with multiple cores.

      Is this Windows?? If so, you can create a private heap that you can use and delete when you are done with it. None of your code that uses that heap needs to clean up after itself since the heap will be deleted.

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        Using pointers as arrays could be faster than using vectors depending on how you are using the vectors. For instance, if you create an empty vector with size 0, then push_back 10 elements, it will take much more time than if you are using a pointer to an array of 10 elements. However, if you use a vector with a predefined size of 10 and fill it, the pointer will not be significantly faster.

        it all depends on what you need to do with the data.

        Comment

        Working...