[PATCH] Reduce memory size of tsearch red-black tree.
Adhemerval Zanella
adhemerval.zanella@linaro.org
Mon Aug 15 17:40:00 GMT 2016
> diff --git a/misc/tsearch.c b/misc/tsearch.c
> index ffb89ec..708239f 100644
> --- a/misc/tsearch.c
> +++ b/misc/tsearch.c
> @@ -83,19 +83,70 @@
> In this case, A has been rotated left. This preserves the ordering of the
> binary tree. */
>
> +#include <assert.h>
> +#include <stdalign.h>
> +#include <stddef.h>
> #include <stdlib.h>
> #include <string.h>
> #include <search.h>
>
> +/* Assume malloc returns naturally aligned (alignof (max_align_t))
> + pointers so we can use the low bits to store some extra info. This
> + works for the left/right node pointers since they are not user
> + visible and always allocated by malloc. The user provides the key
> + pointer and so that can point anywhere and doesn't have to be
> + aligned. */
> +#define CAN_USE_MALLOC_LOW_BIT 1
> +
> +#ifndef CAN_USE_MALLOC_LOW_BIT
Why not enforce alignment with memalign/posix_memalign/aligned_alloc and
drop CAN_USE_MALLOC_LOW_BIT?
More information about the Libc-alpha
mailing list