On 03/01/24 10:36 PM, Bonita Montero wrote:
Am 02.03.2024 um 03:44 schrieb Andrey Tarasevich:
On 03/01/24 5:53 AM, Bonita Montero wrote:
You have been told very clearly already that in this case
`std::function<>` does not perform any memory allocation in Visual
Studio. Neither in Debug nor in Release builds. You imagined it.
Not true ! This code prints "alloc" first with MSVC
and a Debug-build, but not with Release-builds.
???
As you have already been told, your "alloc" originates from
`std::string`, ...
No, from the function allocation. Just single-step the code yourself.
... which is exactly what I did in the first place.
Once again: the Debug config of the _original_ version of the code emits
two allocations, both of which originate in `std::string`. The first one
is allocation of some sort of "container proxy" in `std::string`s
constructor. Another is the same thing in your `[str = str]`.
The updated version of the code (with '[&str]`) emits only one
allocation: the same "container proxy" in `std::string`s constuctor.
No allocations are made for `std::function<>` in either version.
--
Best regards,
Andrey
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)