StringList?

This is a discussion on StringList? within the C++ Programming forums, part of the General Programming Boards category; Thanks guys! Well...I said slower...just because...I don't need all the functionalities of the <list> class...or <vector>...I need only 10 to ...

  1. #16
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    Thanks guys!

    Well...I said slower...just because...I don't need all the functionalities of the <list> class...or <vector>...I need only 10 to 15 functions....and not much! So..why load all the class memebers? besides....I can use basic C/C++ <string.h> rougtines...wcslen....etc...wchar_t type things......so.....it'll work!
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  2. #17
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Except the STL version will be:

    * Exception-safe
    * Virtually memory-leakproof
    * Faster

    For example, if you talk about wsclen(), you need to call that every time you need the length. Which means every single time you need to know the string's length, it has to iterate through the entire string to look for a \0 (and nevermind you might actually want to have a string with embedded NUL characters). A string that is 100 letters long will need 100 characters read from memory, and 100 if() operations before it finally knows and can return the answer.

    In std::wstring, it saves the length when the string is made or changed -- it's not recomputed every time. And length() may well be inlined by your compiler, meaning you don't even have the overhead of a function call. Even for a zero length string -- the fastest possible thing for wcslen() -- it can't be as fast as length(). And wcslen() gets slower and slower as the string gets longer and longer, while length() always takes the same amount of time, for a 1 byte or 100 megabyte string.

    In general, not only will memory management be harder without the STL types, speed is probably slower.

    STL is in general very, very well optimized code. You're not going to outdo it in terms of speed.
    Last edited by Cat; 09-04-2006 at 10:51 PM.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  3. #18
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Moni
    Thanks guys!

    Well...I said slower...just because...I don't need all the functionalities of the <list> class...or <vector>...I need only 10 to 15 functions....and not much! So..why load all the class memebers? besides....I can use basic C/C++ <string.h> rougtines...wcslen....etc...wchar_t type things......so.....it'll work!
    I...don't think....you undestand....how C++....classes work!
    you don't "load all the class memebers". google for "C++ object model" and for the love of god leave the poor ellipisis alone... (d'oh!)
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  4. #19
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    ^ haha...its my habit

    Cat I value your words...let me read more on this...thanks again
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  5. #20
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    If... you... don't... need... all... the... functions... in... the... STL... then... any... decent... linker... will... remove... the... extra... code... for... you...
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  6. #21
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Actually, since all STL types are templates, unless you call the function it won't even compile the function in. E.g. if you never called string::find() it would never even generate that code in the first place; the functions you use are actually compiled into your own .obj files, unlike many library functions which exist, precompiled, in .lib or .dll files.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Am I using *this properly?
    By Sebastiani in forum C++ Programming
    Replies: 3
    Last Post: 12-20-2001, 05:06 PM

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