(no title)
boost_ | 10 years ago
take for example a lot of C++ samples that that guy shows in the video, he calls it "C++11" and uses code like:
- void* data = NULL;
- no STL
- no stack allocations
- only dynamic memory allocation using new and delete
i mean come on..
jeremiep|10 years ago
Stack allocations are discouraged because they can introduce non-deterministic bugs (stack overflow depending on the call sequence which can't be predicted in advance).
Its nearly impossible to write a game without dynamic allocations. Most of the time they'll override the new/delete operators and on that level they work almost exclusively on void*.
You're working on a scale where a lot of the C++ features work against you.
boost_|10 years ago
that’s probably because most of the AAA games you've seen used old in-house libraries that replaced the STL, since the earlier STL implementations weren't the best.
STL is not 100% the way to go every time, but i would say that nowadays unless there’s a really specific implementation need, it should be used at least 90% of the times, even if only for base for new data structures to be built on top of.
- "Stack allocations are discouraged because they can introduce non-deterministic bugs (stack overflow depending on the call sequence which can't be predicted in advance)."
i really don’t understand this problem, you can change the stack size on every compiler and every OS either on compile time or runtime. also, are you writing functions or methods with 10k LoC?
stack allocations are actually easier to follow than heap, its not even close..
- "Its nearly impossible to write a game without dynamic allocations. Most of the time they'll override the new/delete operators"
yes i agree, dynamic allocations are still really needed, and not only for games.
But, overriding new / delete operators in C++ when you can set custom allocators and deallocators for both unique_ptr and shared_ptr? once again i think that’s more of a legacy code update problem than an actually implementation need problem.
- "and on that level they work almost exclusively on void*."
only if they want to, that’s what templates (and again the STL) are here for.
I’m not saying pure C++11/14 features are the only way to go, i just think that at least in new code it should take priority, the cleanness and robustness it provides its just too good to ignore.
marrs|10 years ago