Re: CurrentMemoryContext and MemoryContextStrdup

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: CurrentMemoryContext and MemoryContextStrdup
Дата
Msg-id 14261.1574786901@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: CurrentMemoryContext and MemoryContextStrdup  (Yessica Brinkmann <yessica.brinkmann@gmail.com>)
Список pgsql-novice
Yessica Brinkmann <yessica.brinkmann@gmail.com> writes:
> Thank you very much for the reply!
> Not really, I don't feel better informed because MemoryContextStrdup is not
> even mentioned once in the README.

The next thing to do would be to look at that function's header comment
(find it in src/backend/utils/mmgr/mcxt.c):

/*
 * MemoryContextStrdup
 *        Like strdup(), but allocate from the specified context
 */
char *
MemoryContextStrdup(MemoryContext context, const char *string)


As I recall your original problem, people were suggesting that
you make a longer-lived copy of some transiently-allocated
string.  Copying it into a different context would be the
way to do that, as I hope you now understand from the README
discussion, and this function is the easiest way to do that.

Or at least the second easiest; the very easiest is pstrdup,
which is just

char *
pstrdup(const char *in)
{
    return MemoryContextStrdup(CurrentMemoryContext, in);
}

but I don't remember whether the current context was a suitable
target for your use-case.

            regards, tom lane



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

Предыдущее
От: Yessica Brinkmann
Дата:
Сообщение: Re: CurrentMemoryContext and MemoryContextStrdup
Следующее
От: Yessica Brinkmann
Дата:
Сообщение: Re: CurrentMemoryContext and MemoryContextStrdup