Thread: Storing MemoryContext Pointers
Hi, When I allocate a new memory context via oldmcxt = AllocSetContextCreate(TopMemoryContext, ...) persistent_mcxt = CurrentMemoryContext; How can I store the persistent_mcxt in a persistent place that I'll be able to reach it in my next getting invoked? Is that possible? If not, how can I reach my previously created persistent data in my next invocation? Regards.
Volkan YAZICI <yazicivo@ttnet.net.tr> writes: > When I allocate a new memory context via > oldmcxt = AllocSetContextCreate(TopMemoryContext, ...) > persistent_mcxt = CurrentMemoryContext; ITYM persistent_mcxt = AllocSetContextCreate(TopMemoryContext, ...) because the other doesn't do what you think... > How can I store the persistent_mcxt in a persistent place that I'll be > able to reach it in my next getting invoked? Make it a static variable. regards, tom lane
On Oct 05 03:34, Tom Lane wrote: > Volkan YAZICI <yazicivo@ttnet.net.tr> writes: > > When I allocate a new memory context via > > > oldmcxt = AllocSetContextCreate(TopMemoryContext, ...) > > persistent_mcxt = CurrentMemoryContext; > > ITYM > > persistent_mcxt = AllocSetContextCreate(TopMemoryContext, ...) Opps! Right. (I was looking at some MemoryContextSwitchTo() code while typing above lines.) > because the other doesn't do what you think... > > > How can I store the persistent_mcxt in a persistent place that I'll be > > able to reach it in my next getting invoked? > > Make it a static variable. I had thought some kind of fcinfo->flinfo->fn_extra trick but... a static variable is fair enough too. Thanks so much for the answer (also for your reply to caching subjected post). Regards.
Volkan YAZICI <yazicivo@ttnet.net.tr> writes: > On Oct 05 03:34, Tom Lane wrote: >> Volkan YAZICI <yazicivo@ttnet.net.tr> writes: >>> How can I store the persistent_mcxt in a persistent place that I'll be >>> able to reach it in my next getting invoked? >> >> Make it a static variable. > I had thought some kind of fcinfo->flinfo->fn_extra trick but... a > static variable is fair enough too. No, a fn_extra pointer would go away whenever the calling query ends, and you'd have leaked the context permanently. Children of TopMemoryContext will never go away unless explicitly destroyed, so a static variable has the right lifespan to remember them. If you did want something that goes away at end of query, you could probably make it a child of the PortalContext. regards, tom lane