Expand palloc/pg_malloc API

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Expand palloc/pg_malloc API
Дата
Msg-id bb755632-2a43-d523-36f8-a1e7a389a907@enterprisedb.com
обсуждение исходный текст
Ответы Re: Expand palloc/pg_malloc API  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
Список 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.
Вложения

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

Предыдущее
От: "houzj.fnst@fujitsu.com"
Дата:
Сообщение: RE: bogus: logical replication rows/cols combinations
Следующее
От: Mahendra Singh Thalor
Дата:
Сообщение: Re: Collecting statistics about contents of JSONB columns