Re: Maintaining state across function calls - Mailing list pgsql-general

From Tom Lane
Subject Re: Maintaining state across function calls
Date
Msg-id 1794.1353338925@sss.pgh.pa.us
Whole thread Raw
In response to Maintaining state across function calls  (matt@byrney.com)
Responses Re: Maintaining state across function calls
List pgsql-general
matt@byrney.com writes:
> The question is: what's the "best practice" way of letting a
> C/C++-language function hang onto internal state across calls?

A static variable for that is a really horrid idea.  Instead use
fcinfo->flinfo->fn_extra to point to some workspace palloc'd in the
appropriate context.  If you grep the PG sources for fn_extra you'll
find plenty of examples.

            regards, tom lane


pgsql-general by date:

Previous
From: Benedikt Grundmann
Date:
Subject: Re: How to upgrade postgres 8.4 -> 9.1 contrib?
Next
From: Peter Geoghegan
Date:
Subject: Re: Experiences with pl/Java