Received: from www.credativ.de (cdt1.tz-juelich.de [195.37.52.66]) by postgresql.org (Postfix) with ESMTP id 6A109476183; Thu, 25 Apr 2002 09:02:05 -0400 (EDT) Received: from feivel.credativ.de (feivel.credativ.de [172.26.14.7]) by www.credativ.de (Postfix) with ESMTP id 999ADD6CE1; Thu, 25 Apr 2002 15:07:16 +0200 (CEST) Received: by feivel.credativ.de (Postfix, from userid 1000) id 2EE76A6052; Thu, 25 Apr 2002 15:07:13 +0200 (CEST) Date: Thu, 25 Apr 2002 15:07:13 +0200 From: Michael Meskes To: Lee Kindness Cc: PostgreSQL Interfaces , Mark Aves , PostgreSQL Hackers Subject: Re: ECPG: FETCH ALL|n FROM cursor - Memory allocation? Message-ID: <20020425130713.GC10341@feivel.credativ.de> Mail-Followup-To: Lee Kindness , PostgreSQL Interfaces , Mark Aves , PostgreSQL Hackers References: <15559.60296.332310.657745@kelvin.csl.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <15559.60296.332310.657745@kelvin.csl.co.uk> User-Agent: Mutt/1.3.28i X-Archive-Number: 200204/1347 X-Sequence-Number: 22011 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!