From: Siddhesh Poyarekar <siddhesh@sourceware.org>
To: Andreas Schwab <schwab@linux-m68k.org>,
Siddhesh Poyarekar via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH] realloc: Return unchanged if request is within usable size
Date: Mon, 28 Nov 2022 09:23:08 -0500 [thread overview]
Message-ID: <e67dba8d-3185-6ceb-1287-f91f56b2a862@sourceware.org> (raw)
In-Reply-To: <87v8n222fe.fsf@igel.home>
On 2022-11-25 15:40, Andreas Schwab wrote:
> On Nov 25 2022, Siddhesh Poyarekar via Libc-alpha wrote:
>
>> + /* Smoke test to make sure that allocations do not move if they have enough
>> + space to expand in the chunk. */
>> + for (size_t sz = 3; sz < 256 * 1024; sz += 2048)
>> + {
>> + p = realloc (NULL, sz);
>> + if (p == NULL)
>> + FAIL_EXIT1 ("realloc (NULL, 31) returned NULL.");
>
> s/31/sz/
>
>> + size_t newsz = malloc_usable_size (p);
>> + printf ("size: %zu, usable size: %zu, extra: %zu\n",
>> + sz, newsz, newsz - sz);
>> + void *new_p = realloc (p, newsz);
>> + if (new_p != p)
>
> The compiler is allowed to optimize this to true under the assumption
> that new_p == NULL (the only case where p is still a valid pointer).
>
Hmm, I suppose something like this then?
for (...)
{
...
volatile uintptr_t oldp = p;
void *new_p = realloc (p, newsz)
if (new_p != oldp)
...
}
Thanks,
Sid
next prev parent reply other threads:[~2022-11-28 14:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-25 20:09 Siddhesh Poyarekar
2022-11-25 20:40 ` Andreas Schwab
2022-11-28 14:23 ` Siddhesh Poyarekar [this message]
2022-11-28 14:29 ` Andreas Schwab
2022-11-28 17:26 ` [PATCH v2] " Siddhesh Poyarekar
2022-12-06 22:33 ` DJ Delorie
2022-11-28 9:22 [PATCH] " Wilco Dijkstra
2022-11-28 14:13 ` Siddhesh Poyarekar
2022-12-06 12:45 ` Wilco Dijkstra
2022-12-06 18:41 ` Siddhesh Poyarekar
2023-07-03 22:02 ` Aurelien Jarno
2023-07-04 11:17 ` Siddhesh Poyarekar
2023-07-04 16:08 ` Aurelien Jarno
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=e67dba8d-3185-6ceb-1287-f91f56b2a862@sourceware.org \
--to=siddhesh@sourceware.org \
--cc=libc-alpha@sourceware.org \
--cc=schwab@linux-m68k.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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).