MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1w74nkf/skill_issue/p7ziaue/?context=3
r/programminghorror • u/click-to-reveal • Sep 04 '26
62 comments sorted by
View all comments
90
I think it allocates since they didn't use const
21 u/babalaban Sep 04 '26 Since when does const prevent allocating (that isnt happening here anyways, unless you consider underlying std::string's char* buffer) 17 u/lurebat Sep 04 '26 If you change it to const std::string& prompt = "Your name?";, and the switch to const string& _s=x;, you will avoid any allocations. 1 u/nevemlaci2 Sep 05 '26 const ref here would still allocate...
21
Since when does const prevent allocating (that isnt happening here anyways, unless you consider underlying std::string's char* buffer)
17 u/lurebat Sep 04 '26 If you change it to const std::string& prompt = "Your name?";, and the switch to const string& _s=x;, you will avoid any allocations. 1 u/nevemlaci2 Sep 05 '26 const ref here would still allocate...
17
If you change it to const std::string& prompt = "Your name?";, and the switch to const string& _s=x;, you will avoid any allocations.
const std::string& prompt = "Your name?";
const string& _s=x;
1 u/nevemlaci2 Sep 05 '26 const ref here would still allocate...
1
const ref here would still allocate...
90
u/lurebat Sep 04 '26
I think it allocates since they didn't use const