Re: Q: text palloc() size vs. SET_VARSIZE()

Поиск
Список
Период
Сортировка
Искать
От
Albrecht Dreß
Тема
Re: Q: text palloc() size vs. SET_VARSIZE()
Дата
Msg-id
PUVY7J7E.BZQNEVQM.SPOD3VOP@Q6PR3GHJ.UXWHPUNR.CUL6RPDJ
Ответ на
Список
Дерево обсуждения
Q: text palloc() size vs. SET_VARSIZE() Albrecht Dreß <albrecht.dress@arcor.de>
Re: Q: text palloc() size vs. SET_VARSIZE() Tom Lane <tgl@sss.pgh.pa.us>
Re: Q: text palloc() size vs. SET_VARSIZE() Albrecht Dreß <albrecht.dress@arcor.de>
Am 04.03.18 20:52 schrieb(en) Tom Lane:
> >  From the docs, for me it is not clear whether the value assigned using SET_VARSIZE() must be the *exact* size of the newly allocated return value, or just the length of the text plus the header size.  IOW would the code above create a memory leak if out_len < VARSIZE_ANY_EXHDR(t)?
> 
> No memory leak.  Your returned value would have some wasted memory at the end of its palloc chunk, but function result values don't normally live long enough that that's worth worrying about.

Thanks a lot for the clarification!  I.e. palloc()/pfree() basically behave like malloc()/free() in this regard…

In my application, the wasted space will actually be just a few bytes, if any.  So this is definitely the best solution.

> You could repalloc the result down to minimum size if you felt like it, but I think it'd largely be a waste of cycles.

Avoiding exactly this overhead is my intention!

Thanks again,
Albrecht.
В списке pgsql-general по дате отправления
От: Steve Atkins
Дата:
От: Andre Oliveira Freitas
Дата:
FAQ