Thread: std::string comparison versus int comparison

  1. #1
    Registered User
    Join Date
    Apr 2004
    Location
    Ohio
    Posts
    147

    std::string comparison versus int comparison

    I did a search on google and, naturally, found nothing as I'm apparantly incapable of finding anything this specific.

    Anyway, I've got an OpenGL texture manager. It's very basic and probably inefficient but it does the job -- basically tells me if I need to generate a new GLTexture from an Image resource.

    I check this now by using an integer value which is generated when an Image resource is created. Simple enough.

    However, all Resources as they're build contain a std::string with a unique name. Why not just compare the std::string's instead of an integer?

    The question is, is there a significant difference between comapring a string with a string versus an integer with an integer or is the difference so trivial that it ultimately doesn't matter?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by leeor_net
    The question is, is there a significant difference between comapring a string with a string versus an integer with an integer or is the difference so trivial that it ultimately doesn't matter?
    Comparing two strings can involve comparing all the characters in both of them, which could be considerably more expensive than just comparing two integers when the strings involved are long.
    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
    Apr 2004
    Location
    Ohio
    Posts
    147
    That's what I thought but I wanted to be sure. Thanks for the tip!

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    How are you checking the image vs previously created textures?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  3. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM