Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9826238.cXerOTE6Ve@tjmaciei-mobl5>
Date: Sat, 01 Nov 2025 12:40:41 -0700
From: Thiago Macieira <thiago@...ieira.org>
To: Alejandro Colomar <alx@...nel.org>
Cc: Florian Weimer <fw@...eb.enyo.de>, libc-alpha@...rceware.org,
 musl@...ts.openwall.com, Arthur O'Dwyer <arthur.j.odwyer@...il.com>,
 Jonathan Wakely <jwakely@...hat.com>
Subject: Re: realloci(): A realloc() variant that works in-place

On Saturday, 1 November 2025 09:14:24 Pacific Daylight Time Alejandro Colomar 
wrote:
> -  It will never fail.  It always allocates a size >=MIN(oldsize, size).
> 
> -  When shrinking, either it does actually shrink (if the space can be
>    reused by others), or returns a large size if that space would anyway
>    be wasted.
> 
> -  When growing, it grows to the first step at least as large as the
>    requested size if possible, or it grows as much as possible.  Then
>    it's up to the caller to judge if that's enough.  For example:
> 
>         actual_size = realloci(p, requested_size);
>         if (actual_size < needed_size)
>                 do_actual_realloc();
> 
> Does this sound good for std::vector?

Yes.

I'm pondering whether to also add the "extra" parameter from xallocx(), thus 
making it nearly the same API. I can't think of a good reason, because like 
your proposal, it's documented to

"The xallocx() function returns the real size of the resulting resized 
allocation pointed to by ptr, which is a value less than size if the 
allocation could not be adequately grown in place. "

This means it always returns a value between 
  cursize
and
  ROUND_UP(newsize+extra, blocksize)

Under what circumstances would it make any use of the separation of the two 
values? Is it to make upper layers simpler, by having a constant in the extra 
parameter? Or is it maybe to avoid them having to deal with overflow in the 
addition or multiplication? Does anyone know? We should probably ping Jason 
Evans.

I can see where it's used in the source code, but I haven't spent enough time 
to understand what decisions it may do differently.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Download attachment "signature.asc" of type "application/pgp-signature" (871 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.