Linked Questions

111 votes
11 answers
26k views

Possible Duplicate: Why doesn't GCC optimize structs? Why doesn't C++ make the structure tighter? Consider the following example on a 32 bit x86 machine: Due to alignment constraints, ...
bisgardo's user avatar
  • 4,678
64 votes
7 answers
11k views

[Not a duplicate of Structure padding and packing. That question is about how and when padding occurs. This one is about how to deal with it.] I have just realized how much memory is wasted as a ...
user avatar
72 votes
4 answers
101k views

If I have a struct in C++, is there no way to safely read/write it to a file that is cross-platform/compiler compatible? Because if I understand correctly, every compiler 'pads' differently based on ...
Baruch's user avatar
  • 22k
49 votes
6 answers
16k views

This is a question that was sparked by Rob Walker's answer here. Suppose I declare a class/struct like so: struct { char A; int B; char C; int D; }; Is it safe to assume that these ...
Jason Baker's user avatar
73 votes
3 answers
5k views

I've checked all major compilers, and sizeof(std::tuple<int, char, int, char>) is 16 for all of them. Presumably they just put elements in order into the tuple, so some space is wasted because ...
geza's user avatar
  • 30.5k
30 votes
4 answers
7k views

I know why GCC doesn't re-order members of a structure by default, but I seldom write code that relies on the order of the structure, so is there some way I can flag my structures to be automaticly ...
Maestro's user avatar
  • 9,846
16 votes
2 answers
10k views

Can a C++ compiler (specifically g++) re-order the internal elements of a struct? I'm seeing some strange behaviour where I have a structure that contains something like the following: Struct ...
Lehane's user avatar
  • 48.9k
9 votes
6 answers
4k views

Is the way C++ structs are laid out set by the standard, or at least common across compilers? I have a struct where one of its members needs to be aligned on 16 byte boundaries, and this would be ...
ngoozeff's user avatar
  • 4,776
5 votes
2 answers
1k views

Question: Is there an automatic way to do structure packing? Background: Structure packing is very useful to reduce the memory cost of certain fundamental data. Basically it is the trick to achieve ...
qqibrow's user avatar
  • 3,032
0 votes
3 answers
130 views

I am taking the operating system class in mit online, I completed the first assignement http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-828-operating-system-engineering-fall-...
Baroudi Safwen's user avatar
1 vote
0 answers
607 views

When the compiler (gcc, or intel c++) optimizes a for loop with an index that is a member of a struct, can the compiler break the struct into individual variables/register? For example, when one ...
hamster on wheels's user avatar
0 votes
1 answer
150 views

For example, will gcc/g++(version 9.4, or 7.3) remove unused c and pc in the output file, because this piece of code access only C::i and C::j, but not C::c andC::pc. #include <iostream> ...
Aaron Q's user avatar
  • 38