473,224 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

stl string class performance

Does anyone know if the stl string class implements some sort of pooling or
chunking of memory for performance optimization? I know that the Lucent SCL
has this built in, but not sure if the same is true of STL. The platform is
Solaris 2.8.

Thanks,

Thomas
Jul 19 '05 #1
7 7329

"Thomas" <td*****@att.com> wrote in message news:bl**********@kcweb01.netnews.att.com...
Does anyone know if the stl string class implements some sort of pooling or
chunking of memory for performance optimization? I know that the Lucent SCL
has this built in, but not sure if the same is true of STL. The platform is
Solaris 2.8.


You haven't indicated what implementation you are talking about.

#include <string>
#include <iostream>
using namespace std;

int main() {
string s;
while(true) {
s += " ";
cout << s.size() << " " << s.capacity() << "\n";
}
}

For the G++ version I tried, size and capacity track each other up to 116
charaacters, then the capacity starts jumping 227, 355, 483, 611, 739...
Jul 19 '05 #2
Ron,
Thanks for the feedback. What I was looking for was more along the lines of
a separate pool object, i.e. memory manager, that would handle the memory
allocation for all the objects. Rather than having to ask the o.s for
additional memory, it (string, list, etc) would get it from the pool
object. If the pool object didn't have enough, it would then have to
reallocate. Once the string, list, etc were done with the memory, it would
get returned to the pool object.
My reason for asking is that if SCL has this implementation in place and
the vendor supplying the STL does not, then it is very likely that I can
expect considerable performance degradation when migrating to STL. The
application I support uses strings and lists extensively and would benefit
significantly from that optimization.
I am using the Solaris version that comes with 6.2 on Solaris 8.
Thanks again,
Thomas

"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f*********************@news.newshosting.com. ..

"Thomas" <td*****@att.com> wrote in message

news:bl**********@kcweb01.netnews.att.com...
Does anyone know if the stl string class implements some sort of pooling or chunking of memory for performance optimization? I know that the Lucent SCL has this built in, but not sure if the same is true of STL. The platform is Solaris 2.8.


You haven't indicated what implementation you are talking about.

#include <string>
#include <iostream>
using namespace std;

int main() {
string s;
while(true) {
s += " ";
cout << s.size() << " " << s.capacity() << "\n";
}
}

For the G++ version I tried, size and capacity track each other up to 116
charaacters, then the capacity starts jumping 227, 355, 483, 611, 739...

Jul 19 '05 #3
Thomas wrote:
Ron,
Thanks for the feedback.

<snip>

Please don't top-post. Read section 5 of the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #4
Thomas wrote:
Ron,
Thanks for the feedback. What I was looking for was more along the lines of
a separate pool object, i.e. memory manager, that would handle the memory
allocation for all the objects. Rather than having to ask the o.s for
additional memory, it (string, list, etc) would get it from the pool
object. If the pool object didn't have enough, it would then have to
reallocate. Once the string, list, etc were done with the memory, it would
get returned to the pool object.
I would expect most implementations to be quite optimized, making OS
system calls for every allocation would be quite stupid in most systems.
My reason for asking is that if SCL has this implementation in place and
the vendor supplying the STL does not, then it is very likely that I can
expect considerable performance degradation when migrating to STL. The
application I support uses strings and lists extensively and would benefit
significantly from that optimization.
There isn't such thing as "the STL vendor", The C++ Standard Library is
a specification, there are many different implementations, for instance
every compiler usually has its own Standard Library implementation.
I am using the Solaris version that comes with 6.2 on Solaris 8.
Thanks again,
Thomas


then go to a solaris-specific newsgroup or a newsgroup dedicated to the
compiler you use on solaris and ask them about their implementation of
the Standard Library.

-- Nuclear / the Lab --

Jul 19 '05 #5

"John Tsiombikas (Nuclear / the Lab)" <nu*****@siggraph.org> wrote in
message news:1064611010.658265@athprx02...
My reason for asking is that if SCL has this implementation in place and the vendor supplying the STL does not, then it is very likely that I can
expect considerable performance degradation when migrating to STL. The
application I support uses strings and lists extensively and would benefit significantly from that optimization.


There isn't such thing as "the STL vendor", The C++ Standard Library is
a specification, there are many different implementations, for instance
every compiler usually has its own Standard Library implementation.


He didn't say "the STL vendor". He said "the vendor supplying the STL".
This implies the vendor supplying the STL implementation (see the first half
of the sentence.)
Jul 19 '05 #6

"Thomas" <td*****@erols.com> wrote in message
news:bl**********@bob.news.rcn.net...
Ron,
Thanks for the feedback. What I was looking for was more along the lines of a separate pool object, i.e. memory manager, that would handle the memory
allocation for all the objects.
Rather than having to ask the o.s for
additional memory, it (string, list, etc) would get it from the pool
object. If the pool object didn't have enough, it would then have to
reallocate. Once the string, list, etc were done with the memory, it would
get returned to the pool object.
See the 'allocator' template argument for std::string.
Also don't forget member functions 'reserve()' and 'resize()'.
My reason for asking is that if SCL has this implementation in place and
the vendor supplying the STL does not, then it is very likely that I can
expect considerable performance degradation when migrating to STL.
You can provide your own allocator via a template argument.
The
application I support uses strings and lists extensively and would benefit
significantly from that optimization.


All the containers can have allocator template arguments.

-Mike
Jul 19 '05 #7
In article <bl**********@bob.news.rcn.net>, td*****@erols.com says...
Ron,
Thanks for the feedback. What I was looking for was more along the lines of
a separate pool object, i.e. memory manager, that would handle the memory
allocation for all the objects. Rather than having to ask the o.s for
additional memory, it (string, list, etc) would get it from the pool
object. If the pool object didn't have enough, it would then have to
reallocate. Once the string, list, etc were done with the memory, it would
get returned to the pool object.


There's nothing in the standard to mandate behavior like this, but it's
a fairly accurate description of how things _usually_ work. The
containers in the standard library allow the user to specify an
allocator object that will be used to allocate memory for the
collection. The default allocator will use new and delete to allocate
and free memory.

Since it's not observable behavior (in the way "observable" is meant by
the standard) there's no requirement that new and delete allocate large
chunks of memory from the OS, and sub-allocate out of those. In fact, I
know of one version of one compiler that _did_ use OS calls every time
you allocated or freed memory -- that's a rare (and long-since obsolete)
exception though. Simple market pressure prevents it from becoming
common; nearly everybody has at least a few competitors, and speeding up
the default new and delete will give a competitor a substantial
improvement in both benchmark scores AND in real speed, so most try to
make it at least pretty good (though if it becomes an issue, there are
after-market memory managers that might be worth looking into).

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Oliver S. | last post by:
I've developed a string-class that holds the string in an array which is a member-variable of the class and that has maximum-size which is con- figurable through a template-parameter. If any...
23
by: YinTat | last post by:
Hi, I learned C++ recently and I made a string class. A code example is this: class CString { public: inline CString(const char *rhs) { m_size = strlen(rhs);
4
by: Carl Youngblood | last post by:
I imagine this subject has probably been brought up numerous times. Forgive me for bringing it up again. I was googling through old posts on this newsgroup about it and found a good suggestion on...
27
by: djake | last post by:
In the stroustrup C++ programming language (third edition) i can find example like this: string s1= "Hello"; So I imagine string is a standard class. Furthermore the class in the example is...
13
by: Rob Meade | last post by:
Hi all, I have written a small ProperCase function which I would like to make available to our team at work through our common class library. A colleague mentioned that I could write a new...
7
by: craigkenisston | last post by:
I need an special string that have a fixed capacity and that automatically(silently) trims extra space. MySpecialString str = new MySpecialString(10); str = "1234567890ABCDE" ...
2
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
2
by: Tony Winslow | last post by:
Hi, there! Some users of this group mentioned before that being able to write one's own string class in C++ is a sign of mastering the basics of the language. My problem is that I don't quite...
7
by: Luna Moon | last post by:
#include "stdafx.h" #include <iostream> #include <string> using namespace std; int main() { string cc(31, 'c'); string bb=cc.assign(3, 'dd');
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.