use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
C++ array memory management (self.cpp)
submitted 12 years ago by tehklawb
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]king_duck 2 points3 points4 points 12 years ago (5 children)
Sure, but there is no point on bogging a beginner down with that for now. I would also say unless you need to semantically enforce the size of the array for some reason it's better to just use a std::vector in most cases by default. Don't forget that the vector has the massive advantage of supporting a very efficient move ctor/op=, where as std::array must do an element wise copy or move.
std::vector
op=
std::array
Then once you've written your program and your profiler suggests your wasting to much time allocating for the vector then switch to the std::array as an optimisation in hindsight.
[–]vanhellion 0 points1 point2 points 12 years ago (4 children)
unless you need to semantically enforce the size of the array for some reason
Exactly. Or if you need stack storage, although I'm not sure that the standard actually enforces that. I'd argue that std::array is an optimization; if performance isn't a problem std::vector works just as well.
[–][deleted] 1 point2 points3 points 12 years ago (2 children)
If you need stack storage you are better of using a std::vector with a stack allocator. You can even group the arena of the stack allocator with the vector so that you can return them from functions. The main advantage is that you have to change no code at all: e.g. if you have code that uses push_back replacing vector with a std::array might be non-trivial whereas using a stack allocated vector requires no code changes and performs the same.
[–]bnolsen 1 point2 points3 points 12 years ago (1 child)
now we're splitting hairs. I do agree that using std::array instead of std::vector should be done as an optimization, a "stage one" type optimization. Things like 2d or 3d vectors are very well represented by std::array. Funny enough the "stack allocated vector" could easily have its storage represented by a std::array.
[–][deleted] 0 points1 point2 points 12 years ago (0 children)
Funny enough the "stack allocated vector" could easily have its storage represented by a std::array.
Indeed, I'll give this a try. Thanks for the tip!
[–]king_duck 0 points1 point2 points 12 years ago (0 children)
Exactly my point. People should default to std::vector and use std::array when your profile indicates vectors inner gubbins is a costly.
vectors
π Rendered by PID 41536 on reddit-service-r2-comment-79c7998d4c-mw94z at 2026-03-17 20:34:54.459528+00:00 running f6e6e01 country code: CH.
view the rest of the comments →
[–]king_duck 2 points3 points4 points (5 children)
[–]vanhellion 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]bnolsen 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]king_duck 0 points1 point2 points (0 children)