Is using alloca() for variable length arrays better than using a vector on the heap?
问题 I have some code using a variable length array (VLA), which compiles fine in gcc and clang, but does not work with MSVC 2015. class Test { public: Test() { P = 5; } void somemethod() { int array[P]; // do something with the array } private: int P; } There seem to be two solutions in the code: using alloca(), taking the risks of alloca in account by making absolutely sure not to access elements outside of the array. using a vector member variable (assuming that the overhead between vector and