Re: [dev] dwm bit fields conversion
On 7 July 2013 16:49, koneu <koneu93_AT_googlemail.com> wrote:
> In Xdefs.h, Bool is typedef'd as int (= at least 2 bytes, sometimes more, depending on the implementation), of which we set the last bit to 1 or 0.
> In the Monitor and Client structures dwm uses, we can instead use char bit fields, storing up to 8 Bool values in 1 byte.
>
> diff --git a/dwm.c b/dwm.c
> index 314adf4..83af1f6 100644
> --- a/dwm.c
> +++ b/dwm.c
> _AT_@ -91,7 +91,7 @@ struct Client {
> int basew, baseh, incw, inch, maxw, maxh, minw, minh;
> int bw, oldbw;
> unsigned int tags;
> - Bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
> + unsigned char isfixed :1, isfloating :1, isurgent :1, neverfocus :1, oldstate :1, isfullscreen :1, :2;
> Client *next;
> Client *snext;
> Monitor *mon;
> _AT_@ -121,8 +121,7 @@ struct Monitor {
> unsigned int seltags;
> unsigned int sellt;
> unsigned int tagset[2];
> - Bool showbar;
> - Bool topbar;
> + unsigned char showbar :1, topbar :1, :6;
> Client *clients;
> Client *sel;
> Client *stack;
I find this less readable than the usage of Bool. If memory
consumption would be a major dwm concern, I'd agree with such a
suggestion. But there are more important problems to focus on in dwm
6.1 (fixed xinerama support).
Best regards,
Anselm
Received on Sun Jul 14 2013 - 21:32:27 CEST
This archive was generated by hypermail 2.3.0
: Sun Jul 14 2013 - 21:36:09 CEST