std::string comparison versus int comparison

This is a discussion on std::string comparison versus int comparison within the C++ Programming forums, part of the General Programming Boards category; I did a search on google and, naturally, found nothing as I'm apparantly incapable of finding anything this specific. Anyway, ...

  1. #1
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    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?
    - Leeor

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    Posts
    147
    That's what I thought but I wanted to be sure. Thanks for the tip!
    - Leeor

  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, 03:39 PM
  2. Replies: 3
    Last Post: 05-13-2007, 09:55 AM
  3. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21