Re: Expand palloc/pg_malloc API
Peter Eisentraut <peter.eisentraut@enterprisedb.com>
From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: "David G. Johnston" <david.g.johnston@gmail.com>,
Tom Lane <tgl@sss.pgh.pa.us>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-08-12T07:39:43Z
Lists: pgsql-hackers
On 27.07.22 01:58, David G. Johnston wrote: > 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 think that would also work. Ultimately, it would be more idiomatic (in Postgres), to write this as lockrelid = palloc(sizeof(LockRelId)); and thus lockrelid = palloc_obj(LockRelId);
Commits
-
Add repalloc0 and repalloc0_array
- b4b7ce8061d3 16.0 landed
-
Expand palloc/pg_malloc API for more type safety
- 2864f7755611 10.23 landed
- e962235fe1f6 11.18 landed
- 7dd9b469bc56 12.13 landed
- 172882292451 13.9 landed
- b7f37af7c195 14.6 landed
- 7fe55d5e12b6 15.0 landed
- 2016055a92f2 16.0 landed
-
Assorted examples of expanded type-safer palloc/pg_malloc API
- 5015e1e1b58f 16.0 landed