Re: C language context

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Postgresql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: C language context
Date: 2003-09-05 23:26:15
Message-ID: 26441.1062804375@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> Just how transient is the memory context created for a C language
> function call?

Fairly. IIRC, you'll normally be running in a context that will be
reset at the start of the next tuple cycle for the plan node your
function is evaluated by. If you've got a heavily recursive routine,
it might need to do its own cleanup per-call, but most of the time you
need not bother with pfree.

> I'm still trying to get to the bottom of it, but I want to know if I'm
> safe in relying on the context cleanup to handle things for me. It's an
> immutable text function returning text, and is intended for use in a
> functional index.

You might wanna check the code, but I think we force a context reset
after each tuple for functional index evaluations as well.

AFAIR, the only case where we really still require user-provided
functions to avoid leaking memory is support functions and operators for
indexes (for example, the comparison functions used by btrees). The
internal memory usage in the index AMs is hairy enough to make it
hard to fix that, though I'd like to do so someday.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-09-05 23:44:28 Re: Examining the output of: ldd `which postgres`
Previous Message Rod Taylor 2003-09-05 23:16:17 Re: [PATCHES] Warning for missing createlang