Re: Proposal: add new API to stringinfo

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: michael(at)paquier(dot)xyz
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Proposal: add new API to stringinfo
Date: 2024-12-26 00:53:09
Message-ID: 20241226.095309.352419809664843255.ishii@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Wed, Dec 25, 2024 at 12:37:04PM +0900, Tatsuo Ishii wrote:
>> Attached is a patch to implement it. In the patch I add two new APIs.
>>
>> extern StringInfo makeStringInfoWithSize(int size);
>> extern void initStringInfoWithSize(StringInfo str, int size);
>>
>> Maybe I could re-invent the wheel by copying stringinfo.c, but I think
>> there are some uses cases like me, and it could justify in adding more
>> code to stringinfo.c.
>
> Not sure how other feel about that, but I am not really convinced that
> we need two APIs.

We could make initStringInfoWithSize() as a static function if we
don't want to add two new APIs. The reason it is exported in the patch
is that I thought it maybe useful for callers who use stringinfo in
this pattern.

StringInfoData string;
initStringInfoWithSize(&string);

> Saying that, having more control over the initial
> size used for a StringInfo could provide better practices in some
> cases. This reminds me of the ALLOCSET_SMALL_* fields in memutils.h,
> hence an idea would be an initStringInfoExtended() that you could
> combine with two #define two: one for the "default" of 1024 and a
> second one for "small", like 32 or 64 (?), that can be used at will
> with the new API call. Then you could switch initStringInfo() to
> become a macro of the new "extended" call. Just an idea.

But then the extensions that use stringinfo.c need to be recompiled?

Best reagards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2024-12-26 03:15:42 Re: Proposal: add new API to stringinfo
Previous Message Jelte Fennema-Nio 2024-12-25 23:52:38 Re: Add trim_trailing_whitespace to editorconfig file