You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OOP class with proper attribute ordering, minimizing padding
119
119
Here, padding is reduced by grouping similar types together.
120
120
The attributes are reordered from largest to smallest size (first double, then float, followed by int, char, and finally bool).
@@ -134,8 +134,8 @@ public:
134
134
uint16_t something2; // 2 bytes
135
135
char id; // 1 byte
136
136
bool active; // 1 byte
137
-
// _______
138
-
// 56 bytes total, alignment 8 bytes
137
+
// _______
138
+
// 56 bytes total, alignment 8 bytes
139
139
};
140
140
141
141
atributes mAtributes;
@@ -176,7 +176,7 @@ Again a better result. This indicates that we are not thinking nonsense, but we
176
176
> [!NOTE]
177
177
> Con el comando ```$ lscpu``` you can view the information about my CPU, to see the size in bytes that the CPU queries in each cycle, in order to know how to maximize the efficiency of my structure to avoid unnecessary gaps and perform operations in the fewest number of cycles (L1 and L2 cache sizes, 64-bit data bus size, etc.).
178
178
179
-
### ```Entity_OOP_GoodWithFooPadding````
179
+
### ```Entity_OOP_GoodWithFooPadding```
180
180
Now we manually add the necessary padding to align the data with the 64-bit boundaries of our CPU's memory architecture:
0 commit comments