> 2) "advanced" c++ code:
>
> void foo(const std::string& xxx) { ... };
> int main() { foo("bar"); }
>
> copy-created 2nd string is avoided, but string object to hold "bar" is still must be
> made, 1 malloc(), 1 memcpy().
Are you sure about this? I always thought that foo only receives a pointer to xxx which it puts on the stack, so
no additional malloc/free is involved.
Have a look here: https://en.cppreference.com/w/cpp/language/reference.html
It says "References are not objects; they do not necessarily occupy storage".
Stefan |