C++ temporary object storage
Hi,
We have observed that our stack usage (using -fstack-usage) is growing really fast when temporary c++object is needed. It's look like the compiler doesn't reuse those temporary object.
here a small example:
uint32_t * A(const std::string &a, const std::string &b)
{
return 0;
}
void B()
{
A("test", "test2");
// A("test", "test2");
// A("test", "test2");
// A("test", "test2");
}
The stak usage for B will increase by 16 bytes every call to function A.
When I look at the dissassembly, I see that the std::string object are constructed and destructed at every call of the A function. But the problem I see is that the same temporary object are not reused.
In that case, only 2 temporary object of std::string is needed.
Is it possible to optimize this feature ?
I have looked at different optimisation level and I see that the stack is growing on every call of A.
Regards
Jonathan
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Jonathan Dumaresq for more information if necessary.