Re: Consistently use palloc_object() and palloc_array()

Поиск
Список
Период
Сортировка
От David Geier
Тема Re: Consistently use palloc_object() and palloc_array()
Дата
Msg-id a29b0cd9-576f-486f-ba45-5139ee33adcf@gmail.com
обсуждение исходный текст
Ответ на Re: Consistently use palloc_object() and palloc_array()  (Chao Li <li.evan.chao@gmail.com>)
Ответы Re: Consistently use palloc_object() and palloc_array()
Список pgsql-hackers
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



В списке pgsql-hackers по дате отправления: