Re: Use C11 alignas instead of palloc/malloc for alignment

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Use C11 alignas instead of palloc/malloc for alignment
Date: 2026-09-09 06:52:21
Message-ID: d425b2ca-03a3-481d-a13d-e16999d8358e@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 08.09.26 17:03, Andres Freund wrote:
>> + /*
>> + * These are used to hold the record header while constructing a record.
>> + * 'hdr_scratch' must be MAXALIGNed and padding bytes zeroed.
>> + *
>> + * For simplicity, it's allocated large enough to hold the headers for any
>> + * WAL record.
>> + */
>> + static XLogRecData hdr_rdt;
>> + static alignas(MAXIMUM_ALIGNOF) char hdr_scratch[HEADER_SCRATCH_SIZE];
> I think we really shouldn't add more function level statics at this point. At
> least for file level static variables you can just slap a thread_local on and
> it has a chance of working. But it won't with this.

What would prevent us from adding thread_local to a function-scope
static variable? AFAICT, that should work.

(In this particular case, with Heikki's suggestion, it seems we can get
rid of it.)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-09-09 06:55:40 Re: pg_stat_progress_cluster: do not default to CLUSTER
Previous Message Xuneng Zhou 2026-09-09 05:39:28 Re: Implement waiting for wal lsn replay: reloaded