473,499 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL std::string difference between reserve and resize ()

Hi -
I am going through the STL API for std::string.
I see 2 methods called reserve(sz) and resize(sz) .

I am just curious if they actually implement the same and if not ,
what are the scenarios in which one would be preferable over another.
Dec 18 '07 #1
2 8054
Rakesh Kumar wrote:
I am going through the STL API for std::string.
I see 2 methods called reserve(sz) and resize(sz) .

I am just curious if they actually implement the same and if not ,
Not.
what are the scenarios in which one would be preferable over another.
'resize' changes the size. 'reserve' changes the capacity (so that
some growth didn't require reallocation. 'reserve' does not change
the size. They mean (and do) different things. Use each one when
appropriate.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 18 '07 #2
On Dec 18, 9:11 pm, Rakesh Kumar <rakesh.use...@gmail.comwrote:
Hi -
I am going through the STL API for std::string.
I see 2 methods called reserve(sz) and resize(sz) .

I am just curious if they actually implement the same and if not ,
what are the scenarios in which one would be preferable over another.
http://www.cppreference.com/cppstring/index.html
Dec 19 '07 #3

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

Similar topics

1
5392
by: Axel | last post by:
Hiho, how can I reserve enough memory for a long string? I tried with max_size() but 4GB is to much for my system, an exception ist the result. And I'm getting an exception too when using the...
24
10994
by: Julie | last post by:
I'm re-evaluating the way that I convert from a std::string to char *. (Requirement: the source is a std::string, the usable contents are char *) Here is what I've come up with: #include...
8
2969
by: CoolPint | last post by:
Is there any way I can reduce the size of internal buffer to store characters by std::string? After having used a string object to store large strings, the object seems to retain the large...
4
4231
by: __PPS__ | last post by:
Hello, I have a function that does some decoding (same as urldecode in php) and it returns std::string std::string urldecode(const char* in, std::size_t length); so, this function parses input...
16
16387
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
15
6873
by: roberts.noah | last post by:
Are there any decent benchmarks of the difference between using c strings and std::string out there? Google isn't being friendly about it. Obviously this would be dependant on different...
16
3642
by: yu_kuo | last post by:
Is there any comparison data on perfomance difference between std::string and c style string? Or maybe if there are source code which could be used to measuer on different compiler/platform, in a...
25
8295
by: Bala2508 | last post by:
Hi, I have a C++ application that extensively uses std::string and std::ostringstream in somewhat similar manner as below std::string msgHeader; msgHeader = "<"; msgHeader += a; msgHeader...
5
7224
by: TBass | last post by:
Hi, I'm moving a socket library I wrote from C to C++. In the C version, I had to malloc char arrays to store incoming communication. My hope was to use std::string in C++, but then I realized a...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.