Re: C Style Strings
"Michael Mair" <Michael.Mair@invalid.invalid> skrev i meddelandet
Bo Persson schrieb:
In my particular case, and with some lucky constant propagation
from preceding code, this string constructor results in 5 assembly
basic_string(const value_type* _String,
const allocator_type& _Allocator =
allocator_type() ) : _Parent(_Allocator)
const size_type _StringSize =
if (_MySmallStringCapacity < _StringSize)
Uh, whatever -- this seems somewhat unlike the standard C++ (98)
You don't remember the
basic_string(const charT* s, const Allocator& a = Allocator());
constructor from the standard?
My example is from the implementation I use. The only specific part is
the __forceinline hint, that makes the compiler see that first
inlining the function will then let it optimize most of it away.
Or is that a part of something implementation specific that is
supposed to impress me?
You may not be easily impressed, but to me it seems pretty good to
construct a std::string object in five machine instructions. This is
an object that can later be dynamically extended, should that be
It is also an example of how 10 or so lines of allegedly bloated C++
template code results in just a few machine instructions.
std::string whatever = "abcd";
0040276A mov eax,dword ptr [string "abcd" (434734h)]
0040276F mov dword ptr [esp+28Ch],eax
00402776 mov byte ptr [esp+2A7h],bl
0040277D mov dword ptr [esp+2A8h],ebp
00402784 mov byte ptr [esp+290h],bl
Not bad for a code bloating template! :-)
If you say so -- this is not exactly an assembler language I
am sufficiently fluent in to determine whether this is optimal
in each and every possible situation. The last time I counted
instructions and cycles was on the MC68000...