(sorry if this is a noob question)
Is there any way to allow fixed size C++ arrays in Visual Studio 2019 Community Edition
(i.e int arr[n]
where n is the size I want)
Thanks in advance :D
Asked
Active
Viewed 65 times
0

Nicol Bolas
- 449,505
- 63
- 781
- 982

Cookiebuster
- 3
- 2
-
4That's the opposite of a fixed size array. Variable length arrays are not in the C++ standard and not supported in MSVC++. Use new[] or `_malloca()`. – Hans Passant Dec 17 '20 at 18:27
-
use `std::vector` – Mooing Duck Dec 17 '20 at 19:22
-
Make stack-based allocator and use `std::vector` with it. https://stackoverflow.com/questions/8049657/stack-buffer-based-stl-allocator – Severin Pappadeux Dec 17 '20 at 19:23
1 Answers
0
No. Variable sized arrays are not part of the C++ standard, and Visual Studio does not implement them. Use std::vector
instead.
If you've done measurements that prove that this vector allocation+deallocation is a major slowdown in your app (which I've never seen happen, ever), then consider using a stack-based buffer allocator with the std::vector
.

Mooing Duck
- 64,318
- 19
- 100
- 158
-
Well, difference is that vector would be allocated on heap. What would be more or less equivalent is std::vector with stack based allocator, see https://stackoverflow.com/questions/8049657/stack-buffer-based-stl-allocator – Severin Pappadeux Dec 17 '20 at 19:26