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

memory allocation in postgres

From: Kjetil Haaland <kjetil(dot)haaland(at)student(dot)uib(dot)no>
To: pgsql-novice(at)postgresql(dot)org
Subject: memory allocation in postgres
Date: 2004-11-22 13:28:47
Message-ID: 200411221428.47825.kjetil.haaland@student.uib.no (view raw or flat)
Thread:
Lists: pgsql-novice
Hello all

I have written my own type and a some functions to use in postgres, but i have 
some problems with the memory allocation. In one of the functions, the stuff 
that is inserted is supposed to last until the user logs out, so i have 
changed the memorycontext  to TopMemoryContext like this:
  MemoryContext oldcontext;
  oldcontext = MemoryContextSwitchTo(TopMemoryContext);

and back when the function is done
  MemoryContextSwitchTo(oldcontext);

The problem is, when i allocate memory in some of the other functions it is 
null the first time i call it, and thats correct, but the next time i call 
the same function, what was inserted in the last round is still there. Is 
there away to delete it when the function is finished? I have allocated the 
memory like this:
  char *res1 = NULL;
  char *res2 = NULL;
  res1 = (char *) palloc((inlength+smllength)*sizeof(char));
  res2 = (char *) palloc((inlength+smllength)*sizeof(char));

and then tried to free it in the end (i have read that you don't have to do 
this but i tried it anyway, but it didn't help)
   pfree(res1);
   pfree(res2);

Hope someone can help
Regards, 
Kjetil

Responses

pgsql-novice by date

Next:From: Tom LaneDate: 2004-11-22 16:03:53
Subject: Re: memory allocation in postgres
Previous:From: Alberto Viglione TiscaliDate: 2004-11-22 12:26:04
Subject: unsubscribe

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