On Sat, Sep 10, 2011 at 06:03:23PM -0400, Tom Lane wrote: > I'm considering inventing a new mcxt.c primitive, > > void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent); > > which would have the effect of delinking "context" from its current > parent context and attaching it as a child of the new specified parent. > (Any child contexts that it has would naturally follow along.) > Because of the way that mcxt.c handles parent/child links, there is no > palloc required and so the operation cannot fail.
I like this idea. Currently the only way to control object lifetime is at creation time. This means that you can "atomically" change the lifetime of a collection of object when it reaches a state we like. It occured to me this might be useful in other places where we copy data into a longer lived context after checking. Maybe config file reading or plan construction. The only issue I can think of is if people where allocating in the local context assuming it would be cleaned up and this data got kept as well. So it's probably not appropriate for things that happen really often. Have a nice day, -- Martijn van Oosterhout <klep...@svana.org> http://svana.org/kleptog/ > He who writes carelessly confesses thereby at the very outset that he does > not attach much importance to his own thoughts. -- Arthur Schopenhauer
Description: Digital signature