[FFmpeg-devel] [PATCH 01/16] avutil/buffer: add helper to allocate aligned memory
Michael Niedermayer
michael at niedermayer.cc
Sat Jun 1 00:44:19 EEST 2024
On Fri, May 31, 2024 at 11:06:49PM +0200, averne wrote:
> Le 30/05/2024 à 22:38, Rémi Denis-Courmont a écrit :
> > Le torstaina 30. toukokuuta 2024, 22.43.03 EEST averne a écrit :
> >> This is useful eg. for memory-mapped buffers that need page-aligned memory,
> >> when dealing with hardware devices
> >>
> >> Signed-off-by: averne <averne381 at gmail.com>
> >> ---
> >> libavutil/buffer.c | 31 +++++++++++++++++++++++++++++++
> >> libavutil/buffer.h | 7 +++++++
> >> 2 files changed, 38 insertions(+)
> >>
> >> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
> >> index e4562a79b1..b8e357f540 100644
> >> --- a/libavutil/buffer.c
> >> +++ b/libavutil/buffer.c
> >> @@ -16,9 +16,14 @@
> >> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> >> USA */
> >>
> >> +#include "config.h"
> >> +
> >> #include <stdatomic.h>
> >> #include <stdint.h>
> >> #include <string.h>
> >> +#if HAVE_MALLOC_H
> >> +#include <malloc.h>
> >> +#endif
> >>
> >> #include "avassert.h"
> >> #include "buffer_internal.h"
> >> @@ -100,6 +105,32 @@ AVBufferRef *av_buffer_allocz(size_t size)
> >> return ret;
> >> }
> >>
> >> +AVBufferRef *av_buffer_aligned_alloc(size_t size, size_t align)
> >> +{
> >> + AVBufferRef *ret = NULL;
> >> + uint8_t *data = NULL;
> >> +
> >> +#if HAVE_POSIX_MEMALIGN
> >> + if (posix_memalign((void **)&data, align, size))
> >
> > Invalid cast.
> >
>
> Neither gcc or clang emit a warning here, even on -Weverything.
> What would be your idea of a valid cast then? First cast to intptr_t,
> then void** ?
>
> >> + return NULL;
> >> +#elif HAVE_ALIGNED_MALLOC
> >> + data = aligned_alloc(align, size);
on mingw64:
src/libavutil/buffer.c: In function ‘av_buffer_aligned_alloc’:
src/libavutil/buffer.c:117:12: error: implicit declaration of function ‘aligned_alloc’ [-Werror=implicit-function-declaration]
117 | data = aligned_alloc(align, size);
| ^~~~~~~~~~~~~
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
There will always be a question for which you do not know the correct answer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20240531/62334aaf/attachment.sig>
More information about the ffmpeg-devel
mailing list