Re: Custom Data Type Question - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Custom Data Type Question
Date
Msg-id 19969.1163702606@sss.pgh.pa.us
Whole thread Raw
In response to Re: Custom Data Type Question  (Greg Mitchell <gmitchell@atdesk.com>)
List pgsql-hackers
Greg Mitchell <gmitchell@atdesk.com> writes:
> As far as memory management goes, do I just use hash_create() and assign 
> that pointer to fn_extra and at the end of the query it will be freed? 
> Or will it not be freed until this end of the transaction? I'm really 
> having trouble understanding the memory management issues with Postgres.

You have to be careful that the hashtable is created in the correct
"memory context" --- in this case you want it to be in a query-lifespan
context, not the short-term (per-tuple-lifespan) context that your
function will be called in.  The usual procedure for cases like this is
to use the context identified by fn_mcxt.  src/backend/utils/mmgr/README
might make useful reading for you.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Custom Data Type Question
Next
From: "luis garcia"
Date:
Subject: # of tuples on a Table?