Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-hackers by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group