From: Michael Niedermayer via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Michael Niedermayer <michael@niedermayer.cc>
Subject: [FFmpeg-devel] Re: [PR] avutil/mem: Add av_malloc_with_paddingz() (PR #21509)
Date: Wed, 21 Jan 2026 19:38:15 +0100
Message-ID: <aXEdF-OdJodF5Lzs@neo> (raw)
In-Reply-To: <CABGuwE=OCm9NS+X=2FL5DwrABj_u_Y42V_iP_TBTEH34KQrzNg@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 3459 bytes --]
On Mon, Jan 19, 2026 at 08:44:23AM +0000, Kieran Kunhya via ffmpeg-devel wrote:
> On Mon, 19 Jan 2026, 04:22 michaelni via ffmpeg-devel, <
> ffmpeg-devel@ffmpeg.org> wrote:
>
> > PR #21509 opened by michaelni
> > URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21509
> > Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21509.patch
> >
> > Add a av_malloc() that adds padding like AV_INPUT_BUFFER_PADDING_SIZE
> > and clears it.
> >
> > This is a operation we commonly use so this function should simplify
> > many cases
> >
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> >
> >
> > >From cc424b2a5568ee35a3435ff58a84d2a18c1c6843 Mon Sep 17 00:00:00 2001
> > From: Michael Niedermayer <michael@niedermayer.cc>
> > Date: Mon, 19 Jan 2026 05:15:23 +0100
> > Subject: [PATCH] avutil/mem: Add av_malloc_with_paddingz()
> >
> > Add a av_malloc() that adds padding like AV_INPUT_BUFFER_PADDING_SIZE
> > and clears it.
> >
> > This is a operation we commonly use so this function should simplify
> > many cases
> >
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> > libavutil/mem.c | 10 ++++++++++
> > libavutil/mem.h | 13 +++++++++++++
> > 2 files changed, 23 insertions(+)
> >
> > diff --git a/libavutil/mem.c b/libavutil/mem.c
> > index b205d3fb25..aac7ef4d12 100644
> > --- a/libavutil/mem.c
> > +++ b/libavutil/mem.c
> > @@ -261,6 +261,16 @@ void *av_mallocz(size_t size)
> > return ptr;
> > }
> >
> > +void *av_malloc_with_paddingz(size_t size, size_t padding)
> > +{
> > + if (size > SIZE_MAX - padding)
> > + return NULL;
> > + uint8_t *p = av_malloc(size + padding);
> > + if(p)
> > + memset(p + size, 0, padding);
> > + return p;
> > +}
> > +
> > void *av_calloc(size_t nmemb, size_t size)
> > {
> > size_t result;
> > diff --git a/libavutil/mem.h b/libavutil/mem.h
> > index ab7648ac57..6a4c144f18 100644
> > --- a/libavutil/mem.h
> > +++ b/libavutil/mem.h
> > @@ -129,6 +129,19 @@ void *av_malloc(size_t size) av_malloc_attrib
> > av_alloc_size(1);
> > */
> > void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
> >
> > +/**
> > + * Allocate a memory block with alignment suitable for all memory accesses
> > + * (including vectors if available on the CPU)
> > + *
> > + * An additional padding will be allocated and cleared.
> > + *
> > + * @param size Size in bytes for the memory block to be allocated
> > + * @param padding Size in bytes of padding allocated and zeroed after
> > size.
> > + * @return Pointer to the allocated block, or `NULL` if it cannot be
> > allocated
> > + * @see av_malloc()
> > + */
> > +void *av_malloc_with_paddingz(size_t size, size_t padding)
> > av_malloc_attrib av_alloc_size(1);
> > +
> > /**
> > * Allocate a memory block for an array with av_malloc().
> > *
> > --
> > 2.52.0
> >
> > _______________________________________________
> > ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
> > To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
>
>
> Seems a bit wordy. av_malloc_paddedz instead?
yes, i changed it to james suggestions of av_padded_malloc(),
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 163 bytes --]
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
prev parent reply other threads:[~2026-01-21 23:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 4:21 [FFmpeg-devel] " michaelni via ffmpeg-devel
2026-01-19 8:44 ` [FFmpeg-devel] " Kieran Kunhya via ffmpeg-devel
2026-01-21 18:38 ` Michael Niedermayer via ffmpeg-devel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aXEdF-OdJodF5Lzs@neo \
--to=ffmpeg-devel@ffmpeg.org \
--cc=michael@niedermayer.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git