[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
new module 'aligned-malloc'
From: |
Bruno Haible |
Subject: |
new module 'aligned-malloc' |
Date: |
Tue, 21 Jul 2020 10:47:58 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; ) |
In new gnulib code, I need to allocate memory blocks through malloc() but with
a 16-bytes alignment.
The posix_memalign and memalign functions only help on those platforms where
they exist. It's not possible to emulate posix_memalign or memalign when they
are not present, because when malloc() returned p, we can call free (p)
but not free (p+4) or free (p+8) or similar.
Gnulib has a module 'pagealign_alloc' but it produces a getpagesize() alignment
- not useful (very wasteful) for a 16-bytes alignment.
So here is a module that provides aligned_malloc() and aligned_free().
The alignment is given at compile-time, so that when the desired alignment is
<= the alignment guaranteed by malloc(), there is no overhead. (With an
alignment given at runtime, the aligned_free() function would have to fetch
a back-pointer in all cases, and that means wasting sizeof (void *) bytes
in the case where the desired alignment is small.)
2020-07-21 Bruno Haible <bruno@clisp.org>
aligned-malloc: Add tests.
* tests/test-aligned-malloc.c: New file.
* modules/aligned-malloc-tests: New file.
aligned-malloc: New module.
* lib/aligned-malloc.h: New file.
* m4/malloc-align.m4: New file.
* modules/aligned-malloc: New file.
* doc/posix-functions/posix_memalign.texi: Mention the new module.
* doc/glibc-functions/memalign.texi: Likewise.
0001-aligned-malloc-New-module.patch
Description: Text Data
0002-aligned-malloc-Add-tests.patch
Description: Text Data