Re: [HACKERS] palloc() vs static define?

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [HACKERS] palloc() vs static define?
Дата
Msg-id 199812140401.XAA06755@candle.pha.pa.us
обсуждение исходный текст
Ответ на palloc() vs static define?  (The Hermit Hacker <scrappy@hub.org>)
Список pgsql-hackers
> 
> in commands/cluster.c, in function cluster, we define NewIndexName as:
> 
> char    NewIndexName[NAMEDATALEN]; /* line 93 */
> 
> in function copy_index, we define it as:
> 
> char          *NewIndexName; /* line 246 */
> 
> And then palloc(NAMEDATALEN) before it gets used...
> 
> Now, which we use doesn't much matter to me, but I would think some sort
> of consistency would be in order...or am I missing something as far as
> each are concerned?  Is one method inheriently faster then another, or do
> they have about the same performance characteristics?

Uh, O, Marc is coding.  :-)

cluster.c was written by a hack, and has been cleaned up over time.  You
can use either method.  

> char    NewIndexName[NAMEDATALEN]; /* line 93 */

Allocated stack space on function entry, and releases it on function
exit.

> And then palloc(NAMEDATALEN) before it gets used...

palloc() allocates at function call time, and you have to pfree it, or
wait for transaction to pfree it.  If you are starting/stopping
transactions between palloc() and pfree() you could loose the memory
unless you change to the 'cache' memory context before doing the palloc
and pfree.  See other command/*.c files for examples of this.

--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] Can't 'or' things?
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] Please check: commands/dbcommands.c