Skip to main content

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*

7
  • 2
    Yes, 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..." Commented Jul 4, 2009 at 15:01
  • 3
    True, 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) Commented Jul 4, 2009 at 15:04
  • 4
    One 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. Commented 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... Commented 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. Commented Jun 11, 2018 at 16:03