Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Novice > Re: Postgres 8....
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 3020 of 3323
Post > Topic >>

Re: Postgres 8.3 - C function taking and returning arrays

by tgl@[EMAIL PROTECTED] (Tom Lane) Feb 28, 2008 at 11:55 PM

"s anwar" <sanwar@[EMAIL PROTECTED]
> writes:
> I have written a PostgreSQL 8.3beta2 server side function named
> array_times_scalar (source included below). It works, but I haven't
found
> sufficient examples to be certain that I am not leaking memory. I was
> wondering if someone can either point me to examples or take a look at
the
> code below.

As a rule of thumb, SQL-callable C functions don't need to be
particularly concerned about "leaking" memory allocations made with
palloc().  Such functions are normally called with CurrentMemoryContext
set to a short-lived context that will be reset soon (usually at the
end of the processing cycle for the current tuple).  So anything you
palloc will go away pretty soon anyway.  There's even an argument to be
made that explicit pfree's are a bad idea, because they eat more cycles
than would be needed to let the memory be reclaimed by the next context
reset.

There are some exceptions, in particular functions that are used as
b-tree index sup****t functions need to be more careful.  But for the
most part I'd say don't worry unless you have direct evidence that you
have a problem.

> I am, however, getting incorrect values if I select a particular array
index
> out of the result of this function.

You declared the function as "returns real[]" but the function code
seems to think that it can return some randomly chosen type different
from array of FLOAT4OID.  I think this disconnect is the problem...

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq
 




 2 Posts in Topic:
Postgres 8.3 - C function taking and returning arrays
sanwar@[EMAIL PROTECTED]   2008-02-28 12:53:51 
Re: Postgres 8.3 - C function taking and returning arrays
tgl@[EMAIL PROTECTED] (T  2008-02-28 23:55:42 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 4:52:14 CST 2008.