Re: C-language functions: SRF question - Mailing list pgsql-general

From Tom Lane
Subject Re: C-language functions: SRF question
Date
Msg-id 7867.1271183845@sss.pgh.pa.us
Whole thread Raw
In response to Re: C-language functions: SRF question  (Jorge Arevalo <jorgearevalo@gis4free.org>)
List pgsql-general
Jorge Arevalo <jorgearevalo@gis4free.org> writes:
> BTW, this code is for WKT Raster. A PostGIS extension. We can use the
> memory context I said (fcinfo->flinfo->fn_mcxt) to allocate memory
> when we need to call one of our functions from a standard "version 1"
> function, but is this the right context? I mean, the context we should
> use for a whole-plugin-lifetime persistence.

fn_mcxt will typically point at a query-lifespan context.  If you need
to allocate storage that will live as long as the session, there's not
that much reason not to use malloc, except perhaps that you have to
remember to do your own out-of-memory-failure checks.  The typical
coding pattern in the backend for session-lifespan storage is to use
TopMemoryContext, or possibly make your own context (as a child of
TopMemoryContext) so that you can easily identify how much storage
you're using for this purpose.

            regards, tom lane

pgsql-general by date:

Previous
From: Greg Smith
Date:
Subject: Re: Dynamic Catalog Views
Next
From: A B
Date:
Subject: Re: Need some help with a query (uniq -c)