pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Geier <geidav.pg@gmail.com>
To: Chao Li <li.evan.chao@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Consistently use palloc_object() and palloc_array()
Date: Fri, 28 Nov 2025 22:06:34 +0100
Message-ID: <a29b0cd9-576f-486f-ba45-5139ee33adcf@gmail.com> (raw)
In-Reply-To: <ED821EDD-6A1B-45B8-9005-31BCFFCB5A48@gmail.com>
References: <ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com>
	<ED821EDD-6A1B-45B8-9005-31BCFFCB5A48@gmail.com>

Hi!

Thanks for taking a look.

On 27.11.2025 00:03, Chao Li wrote:
> 
> This is a large patch, I just take a quick look, and found that:
> 
> ```
> -		*phoned_word = palloc(sizeof(char) * strlen(word) + 1);
> +		*phoned_word = palloc_array(char, strlen(word) + 1);
> ```
> 
> And
> 
> ```
> -		params = (const char **) palloc(sizeof(char *));
> +		params = palloc_object(const char *);
> ```
> 
> Applying palloc_array and palloc_object to char type doesn’t seem to improve anything.
> 

You mean because sizeof(char) is always 1 and hence we could instead
simply write:

*phoned_word = palloc(strlen(word) + 1);
params = palloc(1);

I think the _array and _object variants are more expressive and for sure
don't make the code less readable.

--
David Geier





view thread (29+ messages)  latest in thread

Message-ID: <a29b0cd9-576f-486f-ba45-5139ee33adcf@gmail.com>
Permalink:  ../a29b0cd9-576f-486f-ba45-5139ee33adcf@gmail.com/
Also on:    postgresql.org/message-id/a29b0cd9-576f-486f-ba45-5139ee33adcf@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: geidav.pg@gmail.com, li.evan.chao@gmail.com
  Subject: Re: Consistently use palloc_object() and palloc_array()
  In-Reply-To: <a29b0cd9-576f-486f-ba45-5139ee33adcf@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox