Re: Maintaining state across function calls

From: matt(at)byrney(dot)com
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Maintaining state across function calls
Date: 2012-11-19 18:37:03
Message-ID: c2c3b5c6351b3e2666235a729d25eb7a.squirrel@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> matt(at)byrney(dot)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
>

Thanks for this. Out of curiosity, why is a static a bad way to do this?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Welty, Richard 2012-11-19 19:19:57 Re: Experiences with pl/Java
Previous Message Joe Van Dyk 2012-11-19 18:35:04 PITR manual doesn't reference pg_receivexlog?