GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Oct-2008, 21:01
n00pster n00pster is offline
Junior Member
 
Join Date: Sep 2008
Location: Miami
Posts: 40
n00pster will become famous soon enough

Performance of find(string,size_t) in string class of STL


Hello All,

Does any of you know the runtime performance of the following function in string class of STL?

size_t find ( const string& str, size_t pos = 0 ) const;

Also, it would be great if you have any information on how a string is stored (I think a map is stored as red black tree, so maybe string also is stored the same way??)

Regards,
n00pster
  #2  
Old 11-Oct-2008, 22:23
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Performance of find(string,size_t) in string class of STL


Quote:
Originally Posted by n00pster
Also, it would be great if you have any information on how a string is stored (I think a map is stored as red black tree, so maybe string also is stored the same way??)
Given that string::c_str() returns a pointer to a C-style string, I doubt it is implemented as a red-black tree. Sometimes complex solutions are overkill.
  #3  
Old 12-Oct-2008, 00:14
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Performance of find(string,size_t) in string class of STL


What you mean how string is stored ?
  #4  
Old 12-Oct-2008, 01:01
n00pster n00pster is offline
Junior Member
 
Join Date: Sep 2008
Location: Miami
Posts: 40
n00pster will become famous soon enough

Re: Performance of find(string,size_t) in string class of STL


Quote:
Originally Posted by Peter_APIIT
What you mean how string is stored ?
This is what I meant: When a string object is initialized, how does it store the characters internally? Does it use just a char array? I don't think it is stored in a char array. I guess it uses a some data structure that allows fast substring matching.

I did google it, but without luck. I thought may be somebody here might already know so that I don't have to dig more.
  #5  
Old 12-Oct-2008, 01:22
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Performance of find(string,size_t) in string class of STL


Quote:
Originally Posted by n00pster
I don't think it is stored in a char array. I guess it uses a some data structure that allows fast substring matching.
Given that the std::string class has a c_str() member function, I would recommend you access the beginning address of a string. & then step through each element looking at its address. You will find that instances of std::string are simply C-style character arrays.
Quote:
I did google it, but without luck.
A number of Open Source compilers make source available. You can always study the code yourself.
  #6  
Old 12-Oct-2008, 02:04
n00pster n00pster is offline
Junior Member
 
Join Date: Sep 2008
Location: Miami
Posts: 40
n00pster will become famous soon enough

Re: Performance of find(string,size_t) in string class of STL


Quote:
Originally Posted by ocicat
Given that the std::string class has a c_str() member function, I would recommend you access the beginning address of a string. & then step through each element looking at its address. You will find that instances of std::string are simply C-style character arrays..

Oh no, I can't believe I didn't think of this. That was the easiest thing to do. :-) thanks a lot, I checked it and yes you are right without doubt.

Quote:
A number of Open Source compilers make source available. You can always study the code yourself.
I know, but I am out of time now.. really appreciate your fast responses..
  #7  
Old 12-Oct-2008, 20:41
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Performance of find(string,size_t) in string class of STL


Quote:
A number of Open Source compilers make source available. You can always study the code yourself.

What kind of open source compiler do ofer source code ?

I using dev cpp, code blocks and others also.

Thanks.
  #8  
Old 12-Oct-2008, 20:57
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Performance of find(string,size_t) in string class of STL


Quote:
Originally Posted by Peter_APIIT
What kind of open source compiler do ofer source code
GNU's GCC compiler suite.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
Message Class TransformedBG C++ Forum 5 29-Nov-2006 22:28
C++ class -- Please help vnca_1 C++ Forum 3 14-Jun-2006 13:31
a tester class and then some. postage Java Forum 1 06-May-2006 16:48
Help wit my source code compiler errors Krandygrl00 C++ Forum 1 06-Jun-2005 09:14

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:08.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.