Re: [dev] [st] [PATCH] Optimize memory footprint of line buffers

From: suigin <>
Date: Thu, 23 Apr 2015 06:07:28 -0700

On Wed, Apr 22, 2015 at 05:26:37AM -0700, suigin wrote:
> > Another solution would be to allow people to typedef the color index
> > type used by Glyph in config.h, and move the definitions for Glyph,
> > TCursor and Term below where config.h is included in st.c?
> >
> > That way, it makes it easy to customize it for a low memory profile.
> Here's another patch that does what I described. If the name for the
> ColorIndex typdef isn't to your liking, please feel free to change it!

Not so sure this the best way though, now that I've thought about it
some more. How many more colors do people need beyond 256? A handful for
defaultfg, defaultbg, defaultcs, defaultitalic, and defaultunderline.
Maybe a user needs a bunch more for some custom additions, but probably
not thousands more.

Looking at the glyph_attribute enum and mode field of Glyph, there's an
extra 6 bits going unused. One could imagine modifying Glyph to look
like this:

typedef struct {
        uint_least32_t u;
        uint_least32_t mode:12;
        uint_least32_t fg:10;
        uint_least32_t bg:10;
} Glyph;

This way, fg and bg can address a total of 1024 colors, and we have 2
extra bits left over in mode for future use if needed.

The use of bitfields is debatable (GCC can still suck at them in various
cases, but Clang's CG is pretty decent), so if it scares people, the code
could be changed to manually shift and mask off the bits we need, at the
loss of some readability.

Received on Thu Apr 23 2015 - 15:07:28 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 23 2015 - 15:12:08 CEST