Re: Expand palloc/pg_malloc API

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Expand palloc/pg_malloc API
Дата
Msg-id CAKFQuwYtDc29Hhug3XwsvFFqWRSt3K7CAH5U21R7jZ1x0wVBwQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Expand palloc/pg_malloc API  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Expand palloc/pg_malloc API  (Peter Eisentraut <peter.eisentraut@enterprisedb.com>)
Список pgsql-hackers
On Tue, Jul 26, 2022 at 2:32 PM Tom Lane <tgl@sss.pgh.pa.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 *)

В списке pgsql-hackers по дате отправления:

Предыдущее
От: James Coleman
Дата:
Сообщение: Re: [Commitfest 2022-07] Patch Triage: Waiting on Author
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: pg15b2: large objects lost on upgrade