| From: | Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com> | 
|---|---|
| To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | Expand palloc/pg_malloc API | 
| Date: | 2022-05-17 11:41:03 | 
| Message-ID: | bb755632-2a43-d523-36f8-a1e7a389a907@enterprisedb.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
This adds additional variants of palloc, pg_malloc, etc. that 
encapsulate common usage patterns and provide more type safety.
Examples:
-   result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
+   result = palloc_obj(IndexBuildResult);
-   collector->tuples = (IndexTuple *) palloc(sizeof(IndexTuple) *
                                               collector->lentuples);
+   collector->tuples = palloc_array(IndexTuple, collector->lentuples);
One common point is that the new interfaces all have a return type that 
automatically matches what they are allocating, so you don't need any 
casts nor have to manually make sure the size matches the expected 
result.  Besides the additional safety, the notation is also more 
compact, as you can see above.
Inspired by the talloc library.
The interesting changes are in fe_memutils.h and palloc.h.  The rest of 
the patch is just randomly sprinkled examples to test/validate the new 
additions.
| Attachment | Content-Type | Size | 
|---|---|---|
| 0001-Expand-palloc-pg_malloc-API.patch | text/plain | 30.6 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Mahendra Singh Thalor | 2022-05-17 11:44:23 | Re: Collecting statistics about contents of JSONB columns | 
| Previous Message | houzj.fnst@fujitsu.com | 2022-05-17 09:10:00 | RE: bogus: logical replication rows/cols combinations |