Re: Question on alignment - Mailing list pgsql-hackers

From Antonin Houska
Subject Re: Question on alignment
Date
Msg-id 29887.1554122310@localhost
Whole thread Raw
In response to Re: Question on alignment  (Antonin Houska <ah@cybertec.at>)
Responses Re: Question on alignment
Re: Question on alignment
List pgsql-hackers
Antonin Houska <ah@cybertec.at> wrote:

> Since palloc() only ensures MAXIMUM_ALIGNOF, that wouldn't help here anyway.

After some more search I'm not sure about that. The following comment
indicates that MAXALIGN helps too:

/*
 * Use this, not "char buf[BLCKSZ]", to declare a field or local variable
 * holding a page buffer, if that page might be accessed as a page and not
 * just a string of bytes.  Otherwise the variable might be under-aligned,
 * causing problems on alignment-picky hardware.  (In some places, we use
 * this to declare buffers even though we only pass them to read() and
 * write(), because copying to/from aligned buffers is usually faster than
 * using unaligned buffers.)  We include both "double" and "int64" in the
 * union to ensure that the compiler knows the value must be MAXALIGN'ed
 * (cf. configure's computation of MAXIMUM_ALIGNOF).
 */
typedef union PGAlignedBlock
{
    char        data[BLCKSZ];
    double        force_align_d;
    int64        force_align_i64;
} PGAlignedBlock;

-- 
Antonin Houska
Web: https://www.cybertec-postgresql.com



pgsql-hackers by date:

Previous
From: Michael Meskes
Date:
Subject: Re: SQL statement PREPARE does not work in ECPG
Next
From: Michael Paquier
Date:
Subject: Re: Question on alignment