Thread: STD and Performance

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    204

    Question STD and Performance

    When ever I use the STD namespace, my programs become dramatically slower. In other words, C++ things such as string, new, delete, and cout all cause code to run super slow. I get around this by using char*, malloc, free, and printf. Is there any technique, at all, that would allow me to use string, new, delete, and cout without the performance hit?
    Last edited by thetinman; 10-08-2018 at 01:02 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,159
    Quote Originally Posted by thetinman
    When ever I use the STD namespace, my programs become dramatically slower. In other words, C++ things such as string, new, delete, and cout all cause code to run super slow. I get around this by using char*, malloc, free, and printf.
    Is your C code really doing what your C++ code does? For example, a simple use of std::cin with operator>> to read into a std::string object can be more complicated in C than it might initially appear.

    Quote Originally Posted by thetinman
    Is there any technique, at all, that would allow me to use string, new, delete, and cout without the performance hit?
    You should specify your compiler (and hence the standard library implementation) and the compile options that you used. For example, are you compiling at a high optimisation level with NDEBUG defined? If your standard library implementation supports checked iterators, has that feature been disabled?
    Last edited by laserlight; 10-08-2018 at 10:49 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2017
    Posts
    156
    It's very easy to use the STL containers in a poor way causing lots of allocations and deallocations and copying.
    If you show us the code we might be able to show you better ways.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling for performance (GCC)
    By Epy in forum C Programming
    Replies: 9
    Last Post: 06-04-2013, 09:22 AM
  2. Help with Linux and performance
    By Neo1 in forum Tech Board
    Replies: 11
    Last Post: 12-23-2011, 12:12 PM
  3. Tile-map performance
    By VirtualAce in forum Game Programming
    Replies: 41
    Last Post: 04-19-2006, 10:55 PM
  4. SDL Performance problem
    By cboard_member in forum Game Programming
    Replies: 8
    Last Post: 04-09-2006, 01:23 PM
  5. Best performance.
    By Benzakhar in forum Game Programming
    Replies: 3
    Last Post: 01-14-2004, 10:34 AM

Tags for this Thread