Re: CurrentMemoryContext and MemoryContextStrdup
Tom Lane <[email protected]> Tue, 26 Nov 2019 11:48:21 -0500
| Newsgroups | gmane.comp.db.postgresql.novice |
|---|---|
| Message-ID | <[email protected]> |
Yessica Brinkmann <[email protected]> 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