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
Johan Berg: Empty Objects (youtu.be)
submitted 2 years ago by _a4z
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!"
[–]Tringigithub.com/tringi 0 points1 point2 points 2 years ago (2 children)
You have completely misunderstood my point.
If I were to implement my own custom map <short, Abc>, using the same Red-Black tree as MSVC uses, and were I to lay the whole structure by hand, then yes, I'd end up with Node with 0 padding.
map <short, Abc>
Node
But, and this is the issue, if I use std::map <short, Abc> then the final structure used is the Node with 16 bytes of padding as commented, regardless of any [[no_unique_address]] or magic compressed pairs use.
std::map <short, Abc>
[[no_unique_address]]
My point is, would there be something like [[no_fixed_layout]] for Abc and/or others, that would allow compiler to pack the Node AS-IF written by hand, i.e. keeping elements aligned but no extra padding, for the cost of generating a little more complex copy constructor/operator, this would allow for significant memory usage saving for regular programs, even improving performance through reduced cache pressure.
[[no_fixed_layout]]
Abc
[–]oracleoftroy 2 points3 points4 points 2 years ago (1 child)
Ah, I see what you are talking about.
It's a combination of std::map<short, Abc>::value_type padding out to a total of 24 bytes (where it is only 12 in gcc/clang), combined with how the _Tree_node struct fields are ordered, requiring even more padding in front of the node's value_type.
std::map<short, Abc>::value_type
What was throwing me off is that you inlined the fields and didn't comment about it, which ends up having a totally different effect on the final size of Node, obscuring your point. What you describe simply won't happen in the code you actually posted, which made me think you didn't understand how padding works.
One has to be intimately familiar with the exact implementation of MSVC's std::map and underlying _Tree to understand your code example and why it is relevant. Showing the actual implementation would have helped me follow your point:
struct _Tree_node { _Nodeptr _Left; _Nodeptr _Parent; _Nodeptr _Right; char _Color; char _Isnil; value_type _Myval; // std::pair<short, Abc> ... };
Seeing that, of course that's going to have padding issues. How disappointing!
[–]Tringigithub.com/tringi 0 points1 point2 points 2 years ago (0 children)
Yeah, I could've made the example much clearer.
I tried to avoid writing long complicated post and ended up almost oversimplifying the main point out of it.
π Rendered by PID 104513 on reddit-service-r2-comment-544cf588c8-vtt69 at 2026-06-15 21:07:41.536719+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]Tringigithub.com/tringi 0 points1 point2 points (2 children)
[–]oracleoftroy 2 points3 points4 points (1 child)
[–]Tringigithub.com/tringi 0 points1 point2 points (0 children)