Skip site navigation (1) Skip section navigation (2)

Re: [INTERFACES] ECPG: FETCH ALL|n FROM cursor - Memory allocation?

From: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
To: Christof Petig <christof(at)petig-baender(dot)de>
Cc: Michael Meskes <meskes(at)postgresql(dot)org>,Lee Kindness <lkindness(at)csl(dot)co(dot)uk>,PostgreSQL Interfaces <pgsql-interfaces(at)postgresql(dot)org>,Mark Aves <maves(at)csl(dot)co(dot)uk>,PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [INTERFACES] ECPG: FETCH ALL|n FROM cursor - Memory allocation?
Date: 2002-05-06 10:24:36
Message-ID: 15574.23012.920919.499183@kelvin.csl.co.uk (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-interfaces
Okay, lets see if i've got this right...

If I allocate the memory before the FETCH then I (naturally) free
it. However If I NULL initialise the pointer then libecpg will
allocate the memory and I must NOT free it - libecpg will free it
automatically... Yeah?

I think this highlights the need for some documentation on this
aspect.

Regards, Lee Kindness.

Christof Petig writes:
 > Michael Meskes wrote:
 > > On Thu, Apr 25, 2002 at 12:42:00PM +0100, Lee Kindness wrote:
 > >>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.
 > 
 > Never, never mix these two! ECPGfree_auto_mem will free even memory 
 > which has already been free'd by the user, perhaps we should get rid of 
 > this method (any allocated memory regions are stored in a list, if you 
 > never call ECPGfree_auto_mem, this list grows and grows).
 > 
 >     Christof
 > 

In response to

Responses

pgsql-hackers by date

Next:From: Hannu KrosingDate: 2002-05-06 10:48:32
Subject: Re: Native Windows, Apache Portable Runtime
Previous:From: Cyril VELTERDate: 2002-05-06 08:21:37
Subject: Re: Native Windows, Apache Portable Runtime

pgsql-interfaces by date

Next:From: Michael MeskesDate: 2002-05-06 10:59:58
Subject: Re: [INTERFACES] ECPG: FETCH ALL|n FROM cursor - Memory allocation?
Previous:From: Kenny CarruthersDate: 2002-05-06 07:53:47
Subject: Using C functions with triggers

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group