Re: Thinking about inventing MemoryContextSetParent

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Thinking about inventing MemoryContextSetParent
Date: 2011-09-11 10:36:15
Message-ID: 20110911103615.GA28907@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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 <kleptog(at)svana(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2011-09-11 12:24:36 Re: [COMMITTERS] pgsql: Add missing format attributes
Previous Message Dimitri Fontaine 2011-09-11 10:01:45 Re: [REVIEW] prepare plans of embedded sql on function start