pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Meskes <meskes@postgresql.org>
To: Lee Kindness <lkindness@csl.co.uk>
Cc: PostgreSQL Interfaces <pgsql-interfaces@postgresql.org>
Cc: Mark Aves <maves@csl.co.uk>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: ECPG: FETCH ALL|n FROM cursor - Memory allocation?
Date: Thu, 25 Apr 2002 15:07:13 +0200
Message-ID: <20020425130713.GC10341@feivel.credativ.de> (raw)
In-Reply-To: <15559.60296.332310.657745@kelvin.csl.co.uk>
References: <15559.60296.332310.657745@kelvin.csl.co.uk>

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!



view thread (2+ messages)

Message-ID: <20020425130713.GC10341@feivel.credativ.de>
Permalink:  ../20020425130713.GC10341@feivel.credativ.de/
Also on:    postgresql.org/message-id/20020425130713.GC10341@feivel.credativ.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: meskes@postgresql.org, lkindness@csl.co.uk, maves@csl.co.uk, pgsql-hackers@postgresql.org
  Subject: Re: ECPG: FETCH ALL|n FROM cursor - Memory allocation?
  In-Reply-To: <20020425130713.GC10341@feivel.credativ.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox