Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()
Date: Wed, 28 Sep 2022 17:33:02 +0200
Message-ID: <GV1P250MB073795677FB53011E480E03F8F549@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <802092d68ba0f42f23f62ab6a4cc61214d879901.camel@haerdin.se>

Tomas Härdin:
> ons 2022-09-28 klockan 12:48 +0200 skrev Anton Khirnov:
>>
>> +/**
>> + * Reallocate a data buffer, reusing the existing one if it is large
>> enough.
>> + *
>> + * This function is similar to av_realloc(), but optimized for cases
>> where the
>> + * buffer may grow significantly and is not expected to shrink.
>> + *
>> + * @param[in] ptr Previously allocated buffer, or `NULL`. If `ptr`
>> is `NULL`, a
>> + * new uninitialized buffer is allocated. `ptr` is invalidated when
>> this
>> + * function returns non-`NULL` and must be replaced with its return
>> value.
>> + *
>> + * @param[in,out] size Pointer to the allocated size of buffer
>> `ptr`. This
>> + * function updates `*size` to the new allocated size (which may be
>> larger than
>> + * `min_size`). `*size` is set to 0 on failure.
>> + *
>> + * @param[in] min_size Minimum size in bytes of the returned buffer.
>> + *
>> + * @return
>> + * - An allocated buffer (to be freed with `av_free()`) that is
>> large enough to
>> + *   hold at least `min_size` bytes. The first `*size` (value on
>> entry to this
>> + *   function) bytes of the buffer remain the same as the data in
>> `ptr`, the
>> + *   rest is uninitialized.
>> + * - `NULL` on failure, then `*size` is set to 0 and ptr remains
>> untouched.
>> + *
>> + * @see av_realloc()
>> + * @see av_fast_malloc()
>> + */
>> +void *av_realloc_reuse(void *ptr, size_t *size, size_t min_size);
> 
> Isn't it better to return int like av_realloc_array_reuse() and leave
> *ptr and *size untouched on error just as it does? If we're in the
> business of straightening this all out then having all functions work
> the same is less mental load down the line.
> 

IMO size should be unchanged on error, but returning an int is IMO
overblown. I only did it for my version because there is the possibility
of the multiplication overflowing, but that is not the case here.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

      parent reply	other threads:[~2022-09-28 15:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-28 10:48 Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 2/6] lavu: replace av_fast_realloc() with av_realloc_reuse() Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 3/6] lavc: " Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 4/6] lavfi: " Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 5/6] lavf: " Anton Khirnov
2022-09-28 10:48 ` [FFmpeg-devel] [PATCH 6/6] sws: " Anton Khirnov
2022-09-28 10:51 ` [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc() Rémi Denis-Courmont
2022-09-28 10:55   ` Rémi Denis-Courmont
2022-09-28 11:48 ` Tomas Härdin
2022-09-28 15:04   ` Anton Khirnov
2022-09-28 15:33   ` Andreas Rheinhardt [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=GV1P250MB073795677FB53011E480E03F8F549@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /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