Re: Why crash ?
- From: "John Carson" <jcarson_n_o_sp_am_@xxxxxxxxxxxxxxx>
- Date: Sat, 15 Jul 2006 00:26:11 +1000
"Ulrich Eckhardt" <eckhardt@xxxxxxxxxxxxxx> wrote in message
news:tqgko3-qp1.ln1@xxxxxxxxxxxxxxxxxxxxxx
Eberhard Schefold wrote:
Arnaud Debaene schrieb:
That's a side effect of the "small string optimization" :
std::basic_string has an internal 16 bytes buffer that is used to
hold the string content when it is short enough : this avoid
dynamic memory allocation for small strings.
Yes, but naively, I would assume that the optimal buffer size
depended on a certain number of characters, and therefore would
double with wstring. I might well be wrong, though.
The effort to copy said buffer (which contains PODs and can thus be
copied with memcpy) is the same, regardless of what it holds. The
effort to allocate memory dynamically is also the same, no matter
what it will finally contain. Both only depend on the size of the
buffer, so that's a natural approach.
If you are arguing that a buffer size based on bytes rather than characters
is natural, them I am not convinced.
My understanding is that there is a tradeoff between speed and memory usage.
Allocating a large default buffer increases speed if it means that you don't
need to make an additional allocation, but costs extra memory if that buffer
ends up not being fully utilized.
If the foregoing is correct, then it is not obvious that the loss of speed
in going from 15 to 7 characters in the wide character case is justified by
the greater memory saving in that case. That presumably depends on how one
values speed vs memory and on the size distribution of your strings. To take
an extreme case, suppose that all your strings are 15 characters long. Then
if you care at all about speed, you are plainly not going to want a 7
character limit.
--
John Carson
.
- Follow-Ups:
- Re: Why crash ?
- From: Bo Persson
- Re: Why crash ?
- Prev by Date: On runtimes, string wrapping and vs7 / vs8
- Next by Date: Re: Why crash ?
- Previous by thread: On runtimes, string wrapping and vs7 / vs8
- Next by thread: Re: Why crash ?
- Index(es):
Relevant Pages
|