You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
-
2Yes, the link does say it is a matter of performance but is also quite strong in the language it uses i.e. "Do not define a structure...". They could have said "It is not advisable..."Joe– Joe2009-07-04 15:01:23 +00:00Commented Jul 4, 2009 at 15:01
-
3True, the wording does seem a bit strong. But it might be to emphasize that heap-allocated classes aren't slow (as programmers coming from C/C++ might expect)Stack Overflow is garbage– Stack Overflow is garbage2009-07-04 15:04:56 +00:00Commented Jul 4, 2009 at 15:04
-
4One probably answer for the precise number is that a 16-byte structure is still small enough to fit on the CPU's memory bus, or to be copied as part of a SIMD instruction. Larger structures become more complex to copy around or read/write.Stack Overflow is garbage– Stack Overflow is garbage2009-12-22 19:53:01 +00:00Commented Dec 22, 2009 at 19:53
-
1@Backwards_Dave: On a 32-bit platform, copying a multiple of four bytes will be no more expensive than copying 1, 2, or 3 bytes fewer. Likewise for 64-bit platforms and multiples of 8 (and copying 1-7 bytes fewer). Because of the latter point, it makes sense to use a multiple of eight in the recommendation. I think 24 would have been a better choice than 16, but whether a struct or class will be more efficient depends on the usage patterns. There are some usage patterns where a class holding 16 bytes of data would perform better than a struct, and there are some where a struct...supercat– supercat2018-06-11 15:57:22 +00:00Commented Jun 11, 2018 at 15:57
-
2...holding 64 bytes of data would perform better than a class. I think cases where a struct of 24 or fewer bytes would perform significantly less well than a class are outnumbered by those where the class would perform significantly less well.supercat– supercat2018-06-11 16:03:32 +00:00Commented Jun 11, 2018 at 16:03
|
Show 2 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
-
create code fences with backticks ` or tildes ~
```
like so
``` -
add language identifier to highlight code
```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible)
<https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-cs