Re: Do we want a xmalloc or similar function in the Backend?

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Re: Do we want a xmalloc or similar function in the Backend?
Дата
Msg-id 201206191651.14420.andres@2ndquadrant.com
обсуждение исходный текст
Ответ на Re: Do we want a xmalloc or similar function in the Backend?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Tuesday, June 19, 2012 04:38:56 PM Tom Lane wrote:
> Andres Freund <andres@2ndquadrant.com> writes:
> > There are 70+ calls of malloc in the backend in the form of
> > 
> > type* foo = malloc(sizeof(...));
> > if(!foo)
> > 
> >    elog(ERROR, "could not allocate memory");
> > 
> > which is a bit annoying to write at times. Would somebody argue against
> > introducing a function that does the above named xmalloc() or
> > malloc_or_die()?
> 
> 99% of the time, you should be using palloc if that's the behavior you
> want.  I think most of the malloc calls are in places where we want a
> bit more control over the error response.
There are surprisingly many calls that just have the above logic without a 
more elaborate error message. Its mostly cases which allocate memory just once 
and never release it again to avoid having huge static data around for 
processes not using that part of the code.
True enough, most of those could use TopMemoryContext, its a rather 
established pattern not to do so in those cases though...

Andres
-- Andres Freund                       http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training &
Services


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

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: [PATCH 10/16] Introduce the concept that wal has a 'origin' node
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: [PATCH] lock_timeout and common SIGALRM framework