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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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