URL
https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk
Details |
Compare with Previous |
View Log
Line No. |
Rev |
Author |
Line |
1 |
424 |
jeremybenn |
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2 |
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3 |
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Shrink to Fit</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><meta name="keywords" content=" ISO C++ , library " /><link rel="home" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="bk01pt05ch13.html" title="Chapter 13. String Classes" /><link rel="prev" href="bk01pt05ch13s04.html" title="Tokenizing" /><link rel="next" href="bk01pt05ch13s06.html" title="CString (MFC)" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Shrink to Fit</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk01pt05ch13s04.html">Prev</a> </td><th width="60%" align="center">Chapter 13. String Classes</th><td width="20%" align="right"> <a accesskey="n" href="bk01pt05ch13s06.html">Next</a></td></tr></table><hr /></div><div class="sect1" title="Shrink to Fit"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="strings.string.shrink"></a>Shrink to Fit</h2></div></div></div><p>
|
4 |
|
|
</p><p>From GCC 3.4 calling <code class="code">s.reserve(res)</code> on a
|
5 |
|
|
<code class="code">string s</code> with <code class="code">res < s.capacity()</code> will
|
6 |
|
|
reduce the string's capacity to <code class="code">std::max(s.size(), res)</code>.
|
7 |
|
|
</p><p>This behaviour is suggested, but not required by the standard. Prior
|
8 |
|
|
to GCC 3.4 the following alternative can be used instead
|
9 |
|
|
</p><pre class="programlisting">
|
10 |
|
|
std::string(str.data(), str.size()).swap(str);
|
11 |
|
|
</pre><p>This is similar to the idiom for reducing
|
12 |
|
|
a <code class="code">vector</code>'s memory usage
|
13 |
|
|
(see <a class="link" href="../faq.html#faq.size_equals_capacity" title="7.8.">this FAQ
|
14 |
|
|
entry</a>) but the regular copy constructor cannot be used
|
15 |
|
|
because libstdc++'s <code class="code">string</code> is Copy-On-Write.
|
16 |
|
|
</p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk01pt05ch13s04.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk01pt05ch13.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt05ch13s06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Tokenizing </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> CString (MFC)</td></tr></table></div></body></html>
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.