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

Re: Concern about memory management with SRFs

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Concern about memory management with SRFs
Date: 2002-08-29 01:19:54
Message-ID: (view raw or whole thread)
Lists: pgsql-hackerspgsql-patches
Tom Lane wrote:
> I think we should document that any memory that is allocated in the
> first call for use in subsequent calls must come from the memory context
> saved in FuncCallContext (and let's choose a more meaningful name than
> fmctx, please).  This would mean adding code like
> 	oldcontext = MemoryContextSwitchTo(funcctx->fmctx);
> 	...
> 	MemoryContextSwitchTo(oldcontext);
> around the setup code that follows SRF_FIRSTCALL_INIT.  Then it would be
> safe for nodeFunctionscan.c to do a reset before each function call.

That sounds like a good plan.

But can/should we wrap those calls in either existing or new macros? Or 
is it better to have the function author keenly aware of the memory 
management details? I tend to think the former is better.

Maybe SRF_FIRSTCALL_INIT()(init_MultiFuncCall()) should:
- save CurrentMemoryContext to funcctx->per_call_memory_ctx
   (new member of the struct)
- save fcinfo->flinfo->fn_mcxt to funcctx->multi_call_memory_ctx
   (nee funcctx->fmctx)
- leave fcinfo->flinfo->fn_mcxt as the current memory context when it

Then SRF_PERCALL_SETUP() (per_MultiFuncCall()) can change back to 

Would this work?


In response to


pgsql-hackers by date

Next:From: Tom LaneDate: 2002-08-29 01:32:09
Subject: Re: Concern about memory management with SRFs
Previous:From: Bruce MomjianDate: 2002-08-29 01:16:06
Subject: Re: VIRUS IN YOUR MAIL (W32/Klez.h@MM)

pgsql-patches by date

Next:From: Tom LaneDate: 2002-08-29 01:21:09
Subject: Re: Anonymous-record-types omission
Previous:From: Bruce MomjianDate: 2002-08-29 01:15:10
Subject: Re: [HACKERS] fix for palloc() of user-supplied length

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