Re: What is the posix_memalign() equivalent for the PostgreSQL? - Mailing list pgsql-hackers

From Craig Ringer
Subject Re: What is the posix_memalign() equivalent for the PostgreSQL?
Date
Msg-id CAMsr+YENaQkaMGp2nTkYkVL04-Amfyaev-RWuRVV+pzCDxia4w@mail.gmail.com
Whole thread Raw
In response to What is the posix_memalign() equivalent for the PostgreSQL?  (Anderson Carniel <accarniel@gmail.com>)
Responses Re: What is the posix_memalign() equivalent for the PostgreSQL?  (Anderson Carniel <accarniel@gmail.com>)
List pgsql-hackers
On 2 September 2016 at 01:12, Anderson Carniel <accarniel@gmail.com> wrote:
> Dear all,
>
> I am developing an extension for the PostgreSQL that write/read some
> external files from the PostgreSQL. In order to write/read, I am using the
> O_DIRECT flag and using the posix_memalign to allocate memory. I would like
> to know if the postgresql internal library provides an equivalent function
> for the posix_memalign since I am getting unexpected errors.

"unexpected errors". Details please?

If you're trying to allocate aligned memory, I believe PostgreSQL
typically uses the TYPEALIGN macros (see c.h) but I'm painfully
clueless in the area, so ... yeah. Don't trust me.

I was a bit surprised not to see a MemoryContextAlloc or palloc
variant that returns memory aligned to a given boundary.

> All my
> allocations are in the TopMemoryContext since I am working with several
> buffers that must be alive while the PostgreSQL Server is activated.

You can't posix_memalign into TopMemoryContext. Such memory is outside
the memory context system, like memory directly malloc()'d.

-- Craig Ringer                   http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services



pgsql-hackers by date:

Previous
From: Rahila Syed
Date:
Subject: Re: Surprising behaviour of \set AUTOCOMMIT ON
Next
From: Etsuro Fujita
Date:
Subject: Re: Push down more full joins in postgres_fdw