Hello, I noticed that the Glyph struct was using more memory than was needed. Considering that the fg and bg colors have values that are always in the range of [0, 255], there is no need to use a uint32_t for them. A single byte each would suffice. Furthermore, assuming default alignment and packing rules for most target architectures, there was an additional two padding bytes being inserted in between the `mode' and `fg' fields.
The following patch reduces the size of Glyph from 16 bytes to 8 bytes. On a terminal with 240 columns and 124 rows, between both the primary and alternate line buffers, total memory savings are: 2 * 8 * 240 * 124 = 476160 bytes
diff --git a/st.c b/st.c
index 0204b2e..9c8fb86 100644
--- a/st.c
+++ b/st.c
@@ -181,9 +181,9 @@ typedef XftColor Color;
typedef struct {
char c[UTF_SIZ]; /* character code */
- ushort mode; /* attribute flags */
- uint32_t fg; /* foreground */
- uint32_t bg; /* background */
+ ushort mode; /* attribute flags */
+ uchar fg; /* foreground */
+ uchar bg; /* background */
} Glyph;
typedef Glyph *Line;
signature.asc
Description: Digital signature
