Re: Expand palloc/pg_malloc API

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Expand palloc/pg_malloc API
Date: 2022-07-26 23:58:55
Message-ID: CAKFQuwYtDc29Hhug3XwsvFFqWRSt3K7CAH5U21R7jZ1x0wVBwQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jul 26, 2022 at 2:32 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

>
> 2. I don't like the "palloc_ptrtype" name at all. I see that you
> borrowed that name from talloc, but I doubt that's a precedent that
> very many people are familiar with.

> To me it sounds like it might
> allocate something that's the size of a pointer, not the size of the
> pointed-to object. I have to confess though that I don't have an
> obviously better name to suggest. "palloc_pointed_to" would be
> clear perhaps, but it's kind of long.
>

I agree that ptrtype reads "the type of a pointer".

This may not be a C-idiom but the pointed-to thing is a "reference" (hence
pass by value vs pass by reference). So:

palloc_ref(myvariablepointer)

will allocate using the type of the referenced object. Just like _array
and _obj, which name the thing being used as a size template as opposed to
instantiate which seems more like another word for "allocate/palloc".

David J.
P.S.

Admittedly I'm still getting my head around reading pointer-using code (I
get the general concept but haven't had to code them)....

- lockrelid = palloc(sizeof(*lockrelid));
+ lockrelid = palloc_ptrtype(lockrelid);

// This definitely seems like an odd idiom until I remembered about
short-lived memory contexts and the lost pointers are soon destroyed there.

So lockrelid (no star) is a pointer that has an underlying reference that
the macro (and the orignal code) resolves via the *

I cannot reason out whether the following would be equivalent to the above:

lockrelid = palloc_obj(*lockrelid);

I assume not because: typeof(lockrelid) != (*lockrelid *)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2022-07-27 01:09:22 Re: pg15b2: large objects lost on upgrade
Previous Message James Coleman 2022-07-26 23:47:31 Re: [Commitfest 2022-07] Patch Triage: Waiting on Author