Re: ECPG: FETCH ALL|n FROM cursor - Memory allocation? - Mailing list pgsql-interfaces

From Michael Meskes
Subject Re: ECPG: FETCH ALL|n FROM cursor - Memory allocation?
Date
Msg-id 20020425130713.GC10341@feivel.credativ.de
Whole thread Raw
In response to ECPG: FETCH ALL|n FROM cursor - Memory allocation?  (Lee Kindness <lkindness@csl.co.uk>)
List pgsql-interfaces
On Thu, Apr 25, 2002 at 12:42:00PM +0100, Lee Kindness wrote:
> Assuming the following fetch statement in embedded SQL/C:
> 
>  EXEC SQL FETCH ALL IN selectFromTable_cur INTO
>     :array1,
>     :array2;
> 
> is memory automatically allocated (by experimentation I guess so)?

Only if the pointers are NULL. If they have a value libecpg assumes that
this value points to enough memory to store all data.

> Should the input pointers be NULL initialised? How should the memory
> be freed?

A simple free() will do. You also can free all automatically
allocated memory from the most recent executed statement by calling
ECPGfree_auto_mem(). But this is not documented and will never be.

The correct way is to free(array1) and free(array2) while libecpg will
free the internal structures when the next statement is executed.

Michael
-- 
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!


pgsql-interfaces by date:

Previous
From: Lee Kindness
Date:
Subject: ECPG: FETCH ALL|n FROM cursor - Memory allocation?
Next
From: "Yuemin Zhang"
Date:
Subject: ecpg error code -601